//商品列表 0
//添加商品 1
//商品详情 2
//(function(){
define(function(require,exports,module){
	"require:nomunge,exports:nomunge,module:nomunge";
var dialog=require('component-dialog');
var upload=require('component-upload');
//异步请求
var wind_async=require('ddf_wind_async');
var base=require('component-base');
var history=require('component-history');
require('component-page');
var mer_type=require('../../js/merchandise/merchandise_type');

mer_type.init(mer_type);

var keywordsType = "MERCHANDISE_NAME",merStatus = "",keywords="";

var shopId=$("#session_shopid").val();
var ADDFlag=false,EDITFlag=false,TYPEFlag=false;//判断是否有该权限，拥有权限，则出现按钮，否则就不出现按钮
var sysType="",perType="";
var searchSeoWeight = "";// 搜索的商品优先度
var searchSysType = "", searchPerType = "";// 搜索的分类
var beginDate = "", endDate = "";// 更新时间
var beginPrice = "";
var endPrice = "";// 销售价格
var beginInventory = "";
var endInventory = "";// 库存
var sort = "";// 排序条件
var merchandise={};//商品属性数组
var updateMerchandise={};
var seoWeight = "";// 商品优先度
var exportExcel = false, _page = 1,_pageSize = 10,_totalCount = 0;
var provinceId = "", cityId = "", regionId = "";// 省市区
var time = new Date();
var picDefault = "img/pic_bg.png";
var timeStr = time.getFullYear() + "-" + (time.getMonth() + 1) + "-"+ time.getDate();
exports.init = function(m){
		sort = "";
		history.addHis(this,arguments);//增加历史
    	window.$ddf_merchandise = m;

    	mer_type.resetSearchTypeParams();
    	
    	exports.resetSearchParams();
    	
    	var htmlStr = "";
	
		
		htmlStr += '<div id="content-header">';
		htmlStr += '<div id="breadcrumb"> <a href=javascript:load("'+ddf.index.index_js+'") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href="javascript:void(0)" class="current">商品管理</a></div>';

		
		htmlStr += '</div>';
		htmlStr += '<div class="container-fluid">';
		htmlStr += '<div class="row-fluid">';
		htmlStr += '<div class="span12">';
		htmlStr += '<div id="alert-tips0" ></div>';
		htmlStr += '<div class="widget-box">';
		htmlStr += '<div class="widget-title">';
		htmlStr += '<span class="icon">';
		htmlStr += '<i class="icon-search"></i>';
		htmlStr += '</span>';
		htmlStr += '<h5>搜索条件</h5><button type="button" class="label label-success toggle">缩放</button>';
		htmlStr += '</div>        ';
		htmlStr += '<div class="widget-content nopadding">';
		htmlStr += '<form class="form-horizontal">';
		htmlStr += '<div class="row-fluid">';
		htmlStr += '<div class="span6">';
		htmlStr += '<div class="control-group">';
		htmlStr += '<label class="control-label">关键词：</label>';
		htmlStr += '<div class="controls">';
		htmlStr += '<div class="btn-group">';
		htmlStr += '<button data-toggle="dropdown" class="btn dropdown-toggle"><span id="keywordsTypeName">商品名称</span>&nbsp;&nbsp;<span class="caret"></span></button>';
		htmlStr += '<ul class="dropdown-menu">';
		htmlStr += '<li><a href=javascript:$ddf_merchandise.setKeywordsType("MERCHANDISE_NAME","商品名称")>商品名称</a></li>';
		htmlStr += '<li><a href=javascript:$ddf_merchandise.setKeywordsType("BARCODE","商品条码")>商品条码</a></li>';
		htmlStr += '</ul>';
		htmlStr += '</div>';
		htmlStr += ' <input class="span4 m-wrap" type="text" id="keyWord"/>';
		htmlStr += '</div>';
		htmlStr += '</div>';
		htmlStr += '</div>';
		htmlStr += '<div class="span6">';
		htmlStr += '<div class="control-group">';
		htmlStr += '<label class="control-label">商品状态：</label>';
		htmlStr += '<div class="controls">';
		htmlStr += '<div class="btn-group">';
		htmlStr += '<button data-toggle="dropdown" class="btn dropdown-toggle"><span id="merStatusName">全部</span>&nbsp;&nbsp;<span class="caret"></span></button>';
		htmlStr += '<ul class="dropdown-menu">';
		htmlStr += '<li><a href=javascript:$ddf_merchandise.setMerStatus("","全部")>全部</a></li>';
		htmlStr += '<li><a href=javascript:$ddf_merchandise.setMerStatus("shelves","上架")>上架</a></li>';
		htmlStr += '<li><a href=javascript:$ddf_merchandise.setMerStatus("soldOut","下架")>下架</a></li>';
		htmlStr += '<li><a href=javascript:$ddf_merchandise.setMerStatus("recom","推荐")>推荐</a></li>';
		htmlStr += '<li><a href=javascript:$ddf_merchandise.setMerStatus("unrecom","非推荐")>非推荐</a></li>';
		htmlStr += '<li><a href=javascript:$ddf_merchandise.setMerStatus("image","有图")>有图</a></li>';
		htmlStr += '<li><a href=javascript:$ddf_merchandise.setMerStatus("unimage","无图")>无图</a></li>';
		htmlStr += '</ul>';
		htmlStr += '</div> ';
		htmlStr += '</div> ';
		htmlStr += '</div>';
		htmlStr += '</div>';
		htmlStr += '</div>';
		
		htmlStr += '<div class="control-group zindex">';
		htmlStr += '<div class="span6">';
		htmlStr += '<label class="control-label">商品分类：</label>';
		htmlStr += '<div class="controls">';
		htmlStr += '<input id="searchMerSysTypeInput" class="span8 alert_w alert_class_jk" type="text" readonly value="全部" placeholder="商品在系统中的分类，用于商品分类搜索" />';
		htmlStr += '<div class="span8 alert_list_jk">';
		htmlStr += '<ul id="searchMerTypeListSystem">';
		htmlStr += '</ul>';
		htmlStr += '</div>';
		htmlStr += '</div>';
		htmlStr += '</div>';
		htmlStr += '<div class="span6">';
		htmlStr += '<label class="control-label">商品权重：</label>';
		htmlStr += '<div class="controls">';
		htmlStr += '<div class="btn-group">';
		htmlStr += '<button data-toggle="dropdown" class="btn dropdown-toggle"><span id="searchSeoWeightName">全部</span>&nbsp;&nbsp;<span class="caret"></span></button>';
		htmlStr += '<ul class="dropdown-menu">';
		htmlStr += '<li><a href=javascript:$ddf_merchandise.setSeoWeight("searchSeoWeightName","","全部")>全部</a></li>';
		htmlStr += '<li><a href=javascript:$ddf_merchandise.setSeoWeight("searchSeoWeightName","0","普通")>普通</a></li>';
		htmlStr += '<li><a href=javascript:$ddf_merchandise.setSeoWeight("searchSeoWeightName","1","优先")>优先</a></li>';
		htmlStr += '<li><a href=javascript:$ddf_merchandise.setSeoWeight("searchSeoWeightName","2","最优")>最优</a></li>';
		htmlStr += '</ul>';
		htmlStr += '</div>';
		htmlStr += '</div>';
		htmlStr += '</div>';
		htmlStr += '</div>';
		
		htmlStr += '<div class="control-group">';

		htmlStr += '<div class="span6">';
		htmlStr += '<label class="control-label">商品自定义分类：</label>';
		htmlStr += '<div class="controls">';
		htmlStr += '<input id="searchMerTypeInput" class="span8 alert_w alert_class_jk" type="text" value="全部" readonly placeholder="店内商品分类"/>';
		htmlStr += '<div class="span8 alert_list_jk">';
		htmlStr += '<ul id="searchMerTypeListP">';
		htmlStr += '</ul>';
		htmlStr += '</div>';
		htmlStr += '</div>';
		htmlStr += '</div>';
		htmlStr += '<div class="span6"><div class="control-group"><label class="control-label">更新时间：</label><div class="controls"><input class="span4 m-wrap Wdate" type="text" id="beginDate" onClick=WdatePicker({dateFmt:"yyyy-MM-dd",readOnly:false}) onFocus=WdatePicker({maxDate:"#F{$dp.$D(\'endDate\')}"}) />&nbsp;&nbsp;至&nbsp;&nbsp;<input class="span4 m-wrap Wdate" type="text" id="endDate" onClick=WdatePicker({dateFmt:"yyyy-MM-dd",readOnly:false}) onFocus=WdatePicker({minDate:"#F{$dp.$D(\'beginDate\')}"}) /></div></div></div>';

		htmlStr += '</div>';
		
		htmlStr += '<div class="row-fluid"> ';
		htmlStr += '<div class="span6"><div class="control-group"><label class="control-label">商品销售价：</label><div class="controls"><input class="span4 m-wrap" type="text" id="beginPrice" />&nbsp;&nbsp;至&nbsp;&nbsp;<input class="span4 m-wrap" type="text" id="endPrice" /></div></div></div>';
		htmlStr += '<div class="span6"><div class="control-group"><label class="control-label">库存数量：</label><div class="controls"><input class="span4 m-wrap" type="text" id="beginInventory" />&nbsp;&nbsp;至&nbsp;&nbsp;<input class="span4 m-wrap" type="text" id="endInventory" />&nbsp;&nbsp;<input type="checkbox" name="showWarmMer" value="showWarmMer" id="showWarmMer" />只看缺货商品</div></div></div>';
		htmlStr += '</div> ';
		
		htmlStr += '<div class="form-actions">';
		htmlStr += '<button class="btn btn-primary" id="searchMerBtn" type="button" onClick="$ddf_merchandise.searchMerchandise()">搜索</button>';
		htmlStr += ' <button class="btn btn-info" type="button" onClick="$ddf_merchandise.resetSearchParams()">重置</button>';
		htmlStr += '</div> ';
		htmlStr += '</form>';
		htmlStr += '</div>';
		htmlStr += '</div> ';
		htmlStr += '<div class="widget-box">';
		htmlStr += '<div class="widget-title">';
		htmlStr += '<span class="icon">';
		htmlStr += '<i class="icon-pencil"></i>';
		htmlStr += '</span>';
		htmlStr += '<h5>管理商品</h5>';
		htmlStr += '</div>';
		htmlStr += '<div class="widget-content"> ';
		htmlStr += '<div class="div-btn" id="buttonBox">            ';
		htmlStr += '<button class="btn btn-success" id="addMerchandiseBtn" type="button" onclick="$ddf_merchandise.openAddMerchandise()">新增商品</button>';
//		htmlStr += ' <button class="btn btn-warning" id="typeBtn" type="button" onclick=$ddf_merchandise_type.openMerchandiseTypeList("","")>商品分类管理</button>';
		htmlStr += ' <button class="btn btn-primary" id="typeBtn" type="button" onclick=$ddf_merchandise.batchUpdateClose("1")>批量上架</button>';
		htmlStr += ' <button class="btn btn-primary" id="typeBtn" type="button" onclick=$ddf_merchandise.batchUpdateClose("0")>批量下架</button>';
		htmlStr += ' <button class="btn btn-primary" id="typeBtn" type="button" onclick=$ddf_merchandise.batchUpdateRecommend("1")>批量推荐</button>';
		htmlStr += ' <button class="btn btn-primary" id="typeBtn" type="button" onclick=$ddf_merchandise.batchUpdateRecommend("0")>批量取消推荐</button>';
		htmlStr += '</div>';
		htmlStr += '</div>';
		htmlStr += '</div>    ';
		
		htmlStr += '<div class="form-actions">';
		htmlStr += '排序：';
		htmlStr += '<input class="btn btn-tab" id="operTimeSort" type="button" onclick="$ddf_merchandise.operTimeSort()" value="更新时间" />&nbsp;&nbsp;';
		htmlStr += '<input class="btn btn-tab" id="seoWeightSort" type="button" onclick="$ddf_merchandise.seoWeightSort()" value="权重高低" />&nbsp;&nbsp;';
		htmlStr += '<input class="btn btn-tab" id="inventorySort" type="button" onclick="$ddf_merchandise.inventorySort()" value="库存量" />&nbsp;&nbsp;';
		htmlStr += '<input class="btn btn-tab" id="saleSort" type="button" onclick="$ddf_merchandise.saleSort()" value="销售量" />&nbsp;&nbsp;';
		htmlStr += '<input class="btn btn-tab" id="priceSort" type="button" onclick="$ddf_merchandise.priceSort()" value="销售价" />&nbsp;&nbsp;';
		htmlStr += '<input class="btn" id="defSort" type="button" onclick="$ddf_merchandise.defSort()" value="默认" />&nbsp;&nbsp;';
		htmlStr += '</div> ';
		
		htmlStr += '<div class="widget-box">';
		//htmlStr += '<div id="widget-box-waiting" class="widget-box waiting">';
		htmlStr += '<div class="widget-title"> <span class="icon"><i class="icon-th"></i></span>';
		htmlStr += '<h5>商品列表(温馨提示:带"<font color="#F66">★</font>"的列可直接双击编辑)</h5>';
		//htmlStr += '<a class="label label-success">刷新</a>';
		htmlStr += '</div>';
		htmlStr += '<div class="widget-content nopadding dataTables_wrapper">';
		htmlStr += '<table class="table table-bordered data-table">';
		htmlStr += '<thead>';
		htmlStr += '<tr>';
		htmlStr += '<th><input type="checkbox" id="checkbox_merchandise" onclick="$ddf_merchandise.checkboxMerchandise()" /></th>';
		htmlStr += '<th>序号</th>';
		htmlStr += '<th>商品条码</th>';
		htmlStr += '<th width="8%"><font color="#F66">★</font>商品名称</th>';
		htmlStr += '<th><font color="#F66">★</font>库存</th>';
		htmlStr += '<th><font color="#F66">★</font>市场价 /元</th>';
		htmlStr += '<th><font color="#F66">★</font>销售价 /元</th>';
		htmlStr += '<th>总销量</th>';
		htmlStr += '<th width="5%">商品所属系统类别</th>';
		htmlStr += '<th width="5%">商品自定义类别</th>';
		htmlStr += '<th>是否上下架</th>';
		htmlStr += '<th>是否推荐</th>';
		htmlStr += '<th>权重</th>';
		htmlStr += '<th>更新时间</th>';
		htmlStr += '<th>操作</th>';
		htmlStr += '</tr>';
		htmlStr += '</thead>';
		htmlStr += '<tbody  id="merchandiseList">';

		htmlStr += '</tbody>';
		htmlStr += '</table>';
		htmlStr += '<div  id="footPageDiv0">';
		
		htmlStr += '</div>';
		htmlStr += '</div>';
		//htmlStr += '</div>';
		htmlStr += '</div>';
		htmlStr += '</div>';
		htmlStr += '</div>';
		htmlStr += '</div>';
		  

//    	$("#content0").css("display","block");
		showDiv("content0");
    	
    	$("#content0").html(htmlStr);

    	
    	//base.setDropdownMenu();
    	getErpMerchandiseTypesListSystem("", "searchPage");
		getErpMerchandiseTypesList("", "searchPage");
    	getMerchandiseList(1,pageSize,keywordsType,keywords,merStatus);


}

/**
 * 批量选择商品
 */
exports.checkboxMerchandise=function() {
	
	if ($('#checkbox_merchandise').attr('checked')) {
		
		$("input[name='checkbox_merchandise']").attr("checked", "checked");
	} else {
		$("input[name='checkbox_merchandise']").removeAttr("checked");
	}
};

/**
 * 批量上下架
 */
exports.batchUpdateClose=function(closed) {
	
	var params={
		closed:closed
	};
	var num = 0;
	
	var chk = document.getElementsByName("checkbox_merchandise");
	
	for (var i = 0; i < chk.length; i++) {
		if (chk[i].checked == true) {
			
			params["checkbox_merchandise["+num+"]"]=chk[i].value;
			num++;  
		}
	}
	if (num == 0) {
		base.tips_error("请至少选择一件商品");
		return false;
	} else {
		
		base.showLoading();
				
		eval(Wind.compile("async",function(){
			
			var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.merchandise.batchUpdateClose,params));
			
			if(data.code=="1"){

				$("input[name='checkbox_merchandise']").removeAttr("checked");
				
				$("#checkbox_merchandise").removeAttr("checked");

				
				
				base.tips(data.message);
				
			}else{
				
				base.tips_error(data.message);
			}
			

			base.cancelLoading();
			$("#searchMerBtn").click();
		}))().start();
		
		return true;
	}
};

/**
 * 批量推荐和取消
 */
exports.batchUpdateRecommend=function(recommend) {
	
	var params={
			recommend:recommend
	};
	var num = 0;
	
	var chk = document.getElementsByName("checkbox_merchandise");
	
	for (var i = 0; i < chk.length; i++) {
		if (chk[i].checked == true) {
			
			params["checkbox_merchandise["+num+"]"]=chk[i].value;
			num++;  
		}
	}
	if (num == 0) {
		base.tips_error("请至少选择一件商品");
		return false;
	} else {
		
		base.showLoading();
				
		eval(Wind.compile("async",function(){
			
			var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.merchandise.batchUpdateRecommend,params));
			
			if(data.code=="1"){

				$("input[name='checkbox_merchandise']").removeAttr("checked");
				
				$("#checkbox_merchandise").removeAttr("checked");

				
				
				base.tips(data.message);
				
			}else{
				
				base.tips_error(data.message);
			}
			

			base.cancelLoading();
			$("#searchMerBtn").click();
		}))().start();
		
		return true;
	}
};




/**
 * 查询商品列表
 * @param pageNumber
 * @param keywordsType
 * @param keywords
 * @param merStatus
 */
function getMerchandiseList(pageNumber,pageSize,keywordsType,keywords,merStatus){
	
	keyWords=$("#keyWord").val();
	var isWarmMer = $('input[name="showWarmMer"]:checked').val();
	var params={
			"page.pageNumber":pageNumber,
			"page.pageSize" : pageSize,
			"keywordsType":keywordsType,
			"keywords":keyWords,
			"merStatus":merStatus,
			"sysType" : searchSysType,
			"perType" : searchPerType,
			"beginDate" : beginDate,
			"endDate" : endDate,
			"beginPrice" : beginPrice,
			"endPrice" : endPrice,
			"beginInventory" : beginInventory,
			"endInventory" : endInventory,
			"seoWeight" : searchSeoWeight,
			"sort" : sort,
			"isWarmMer":isWarmMer,
			"shopId":shopId
	        };
	

	base.showLoading();
		
//	DDF_AsyncRequest("POST",ddf.merchandise.getMerchandiseList,params,'$ddf_merchandise.getMerchandiseListCallBack(data)');
	eval(Wind.compile("async",function(){
		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.merchandise.getMerchandiseList,params));
		getMerchandiseListCallBack(data);
	}))().start();
	
}

/**
 * 查询商品列表_回调函数
 */
function getMerchandiseListCallBack(data){
		
		if(data["ADD"]!=true){
			$("#addMerchandiseBtn").css("display","none");
			
		}
		if(data["TYPE"]!=true){
			$("#typeBtn").css("display","none");
		}else{
			TYPEFlag=true;
		}
		if(data["EDIT"]==true){
			EDITFlag=true;
		}
	if(data["code"]==1){
		var htmlStr="";
		
		for(var i=0;i<data["merchandiseListData"].length;i++){

			htmlStr += '<tr>';
			htmlStr += '<td style="text-align:center;"><input type="checkbox" name="checkbox_merchandise" value="'+data["merchandiseListData"][i]["MERCHANDISE_ID"]+'" /></td>';
			htmlStr += '<td>'+getSequence(data["pageNumber"],i+1)+'</td>';
			htmlStr += '<td>'+data["merchandiseListData"][i]["BARCODE"]+'</td>';
			htmlStr += '<td>'+data["merchandiseListData"][i]["MERCHANDISE_NAME"]+'</td>';
			htmlStr += '<td>'+data["merchandiseListData"][i]["INVENTTORY"]+' </td>';
			htmlStr += '<td>'+data["merchandiseListData"][i]["MKTPRICE"]+'</td>';
			htmlStr += '<td>'+data["merchandiseListData"][i]["SALEPRICE"]+'</td>';
			htmlStr += '<td>'+data["merchandiseListData"][i]["COUNTSALES"]+'</td>';
			htmlStr += '<td>'+data["merchandiseListData"][i]["merchandiseTypeName"]+'</td>';
			
			htmlStr += '<td>'+data["merchandiseListData"][i]["shopMerchandiseTypeName"]+'</td>';
			htmlStr += '<td>'+(data["merchandiseListData"][i]["CLOSED"] == "1"?"<span style='color:blue;'>上架</span>":"<span style='color:red;'>下架</span>")+'</td>';
			htmlStr += '<td>'+(data["merchandiseListData"][i]["RECOMMENDED"] == "1"?"推荐":"非推荐")+'</td>';
			if(data["merchandiseListData"][i]["SEO_WEIGHT"] == '0'){
				htmlStr += '<td>普通</td>';
			}else if(data["merchandiseListData"][i]["SEO_WEIGHT"] == '1'){
				htmlStr += '<td>优先</td>';
			}else if(data["merchandiseListData"][i]["SEO_WEIGHT"] == '2'){
				htmlStr += '<td>最优</td>';
			}else {
				htmlStr += '<td>'+data["merchandiseListData"][i]["SEO_WEIGHT"]+'</td>';
			}
			htmlStr += '<td>'+data["merchandiseListData"][i]["UPDATE_TIME"]+'</td>';
			htmlStr += '<td><a href=javascript:$ddf_merchandise.loadMerchandiseDetail("'+data["merchandiseListData"][i]["MERCHANDISE_ID"]+'")>详情</a></td>    ';
			htmlStr += '</tr> ';
			
		}
		
		$("#merchandiseList").html(htmlStr);
		
		var dbClick=true;
		
		$("#merchandiseList tr").each(function(position){
			
			$("#merchandiseList tr:eq("+position+") td:eq(3)," +
			  "#merchandiseList tr:eq("+position+") td:eq(4)," +
			  "#merchandiseList tr:eq("+position+") td:eq(5)," +
			  "#merchandiseList tr:eq("+position+") td:eq(6)").dblclick(function(){
			
				if(!dbClick)
					return;
				
				dbClick=false;
				
		        var inval = $(this).html().trim();  
		        
		        var index=parseInt($(this).index());
		        
		        var merchandiseId=$(this).parent().find("td:eq(0) input").attr("value"); 
		        
				$(this).html("<input class='span12' style='margin-bottom:0px;' type='text' id="+merchandiseId+" value='"+inval+"'>");
		        
		        
			    $("#"+merchandiseId).focus().blur(function(){
			    	
			           var editval = $(this).val(); 
			            
			           var params={
			        			"merchandiseId":merchandiseId
			        	};
			           if(index==3){
			        	   
			        	   params["merchandiseName"]=editval;
			        	   
			        	   if(isNull(editval)){
			        		   
			        			base.tips_error("商品名称非法");
			        			$(this).parent().html(inval); 
			        			dbClick=true;
			        			return;
			        			
			        		}else if(isLength(editval,80)){
			        			
			        			base.tips_error("商品名称不要超过40个字");
			        			$(this).parent().html(inval); 
			        			dbClick=true;
			        			return;
			        		}
			        	   
			           }else if(index==4){
			        	   
			        	   params["inventory"]=editval;
			        	   
			        	   if(isNull(editval) || !isPositiveInteger(editval)){
			        		   
			        		    base.tips_error("库存数量非法");
			        		    $(this).parent().html(inval); 
			        		    dbClick=true;
			        		    return;
			        		}
			        	   
			           }else if(index==5){
			        	   
			        	   params["mktprice"]=editval;
			        	   
			        	   if(isNull(editval) || !isMerPrice(editval)){
			        		   
			        		   base.tips_error("市场价格非法,只能输入整数,或带两位小数的数字");
			        		   
					           $(this).parent().html(inval); 
					           dbClick=true;
							   return;
							}
			        	   
			           }else if(index==6){
			        	   
			        	   params["salePrice"]=editval;
			        	   
			        	   if(isNull(editval) || !isMerPrice(editval)){
			        		   
			        		   base.tips_error("销售单价非法,只能输入整数,或带两位小数的数字");
			        		 
			        		   $(this).parent().html(inval); 
			        		   dbClick=true;
							   return;
							}
			           }
			            
			           //如果值是相同的,则不做修改
			           if(inval==editval){
			        	   
			        	   $(this).parent().html(inval); 
			        	   dbClick=true;
			        	   return;
			           }
			       
			            base.showLoading();
			           
			        	eval(Wind.compile("async",function(){
			        		
			        		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.merchandise.updateMerchandiseField,params));
			        		
			        		if(data.code=="1"){
			        			
			        			base.tips(data.message);
			        			
			        			$("#"+merchandiseId).parent().html(editval); 
			        			
			        		}else{
			        			
			        			base.tips_error(data.message);
			        			
			        			$("#"+merchandiseId).parent().html(inval); 
			        		}
			        		base.cancelLoading();
			        		
			        		dbClick=true;
			        	}))().start();
			        	
			        	
			        	
			            
			    });
		    
		    });
			
			
		});
	

//		setPage(0,data["pageNumber"],data["totalCount"],data["totalPage"],"$ddf_merchandise");
		$('#footPageDiv0').ddf_pagination(data["pageSize"],data["pageNumber"],data["totalCount"],data["totalPage"],{  
			 changePageCallback:function(pageSize,page){
				 _page=page;
				 _pageSize=pageSize;
				 getMerchandiseList(page,pageSize,keywordsType,keywords,merStatus);
			 },
			 changePageSizeCallBack:function(pageSize){
				 _page=1;
				 _pageSize=pageSize;
				 getMerchandiseList(1,pageSize,keywordsType,keywords,merStatus);
			 } 
	     }); 
	}else{
		
		base.tips_error(data["message"]);
	}

	base.cancelLoading();
}


/**
 * 重置参数
 */
function resetSearchParams(){
	
	keywordsType = "MERCHANDISE_NAME";
	merStatus = "";
	searchSeoWeight = "";// 商品优先度
	searchSysType = "", searchPerType = "";// 分类
	beginDate = "", endDate = "";// 更新时间
	beginPrice = "";
	endPrice = "";// 销售价格
	beginInventory = "";
	endInventory = "";// 库存
	sort = "";// 排序条件

	$("input[name='showWarmMer']").attr("checked",false);
	$("#keyWord").val("");
	$("#keywordsTypeName").html("商品名称");
	$("#merStatusName").html("全部");
	$("#searchSeoWeightName").html("全部");
	$("#searchMerSysTypeInput").val("全部");
	$("#searchMerTypeInput").val("全部");
	$("#beginDate").val("");
	$("#endDate").val("");
	$("#beginPrice").val("");
	$("#endPrice").val("");
	$("#beginInventory").val("");
	$("#endInventory").val("");

	_page = 1;
	_pageSize = 10;
	_totalCount = 0;
	exportExcel = false;
}
/**
 * 搜索商品
 */
function searchMerchandise(){

	beginDate = $("#beginDate").val();
	endDate = $("#endDate").val();
	beginPrice = $("#beginPrice").val();
	endPrice = $("#endPrice").val();
	beginInventory = $("#beginInventory").val();
	endInventory = $("#endInventory").val();
	seoWeight = $('input[name="merchandise.seoWeight"]:checked').val();
	if (!isNull(beginPrice) && !isMerPrice(beginPrice)) {
		base.tips_error("开始销售金额非法");
		return;
	}

	if (!isNull(endPrice) && !isMerPrice(endPrice)) {
		base.tips_error("结束销售金额非法");
		return;
	}

	if (parseFloat(beginPrice) > parseFloat(endPrice)) {
		base.tips_error("开始销售金额不能大于结束销售金额");
		return;
	}

	if (!isNull(beginInventory) && !isNumber(beginInventory)) {
		base.tips_error("开始库存数量非法");
		return;
	}

	if (!isNull(endInventory) && !isNumber(endInventory)) {
		base.tips_error("结束库存数量非法");
		return;
	}

	if (parseFloat(beginInventory) > parseFloat(endInventory)) {
		base.tips_error("开始库存数量不能大于结束库存数量");
		return;
	}

	getMerchandiseList(_page, _pageSize, keywordsType, keywords, merStatus);

}

/**
 * 设置关键字类型
 * @param type
 */
function setKeywordsType(type,name){
	
	keywordsType=type;
	
	$("#keywordsTypeName").html(name);
}

/**
 * 设置商品状态
 * @param status
 */
function setMerStatus(status,name){
	
	merStatus=status;
	
	$("#merStatusName").html(name);
}

/**
 * 打开添加商品
 */
function openAddMerchandise(){
	history.addHis(this,arguments);//增加历史
	seoWeight = "0";
	sMerchandiseTypeId="";
	unitCode="";
	vendorId="";
	parentId="";
	defImgPath="";
	sysType="";
	perType="";
	base.showLoading();
	
	goodsPicArray = new Array();//清除图片变量
	
	$("#content4").html("");
	
	var htmlStr="";
	
	htmlStr += '<div id="content-header">';
	htmlStr += '<div id="breadcrumb"> <a href=javascript:load("'+ddf.index.index_js+'",1,"$ddf_index.loadIndex","") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href=javascript:$ddf_merchandise.showDiv("content0")>商品管理</a><a href="javascript:void(0)" class="current">添加商品</a></div>';
	htmlStr += '</div>    ';

	htmlStr += '<div class="container-fluid">';
	htmlStr += '<div class="row-fluid">';
	htmlStr += '<div class="span12">    	';
	htmlStr += '<div id="alert-tips1" ></div>';
	htmlStr +='<div id="errorMessage-addMer" style="display:none" class="alert alert-error alert-block">';
	htmlStr +='<a class="close" href="#" data-dismiss="alert">×</a>';
	htmlStr +='<h4 class="alert-heading">Error!</h4>';
	htmlStr +='You are not looking too good. Nulla vitae elit libero, a pharetra augue. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.';
	htmlStr +='</div>  ';
	
	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title">';
	htmlStr += '<span class="icon"><i class="icon-pencil"></i></span>';
	htmlStr += '<h5>操作</h5>';
	htmlStr += '</div>  ';
	htmlStr += '<div class="widget-content">';
	// htmlStr += '<div class="form-actions">';
	htmlStr += '<span id="saveAndNewButton"><button class="btn btn-success" type="button" onclick="$ddf_merchandise.saveAndNew()" >保存并继续添加</button></span>';
	htmlStr += ' <span id="saveButton"><button class="btn btn-primary" type="button" onclick="$ddf_merchandise.saveNext()" >保存商品</button></span>';
	htmlStr += ' <button class="btn btn-info" type="button" onClick=$ddf_merchandise.showDiv("content0")>返回</button>      ';
	// htmlStr += '</div> ';
	htmlStr += '</div>';
	htmlStr += '</div>';
	
	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title"> <span class="icon"><i class="icon-th"></i></span>';
	htmlStr += '<h5>添加商品</h5>';
	htmlStr += '</div>';
	htmlStr += '<div class="widget-content nopadding">';
	htmlStr += '<div class="form-horizontal">	';
	
	htmlStr += '<div class="control-group">';
	htmlStr += '<div class="span6" id="control-group-barcode">';
	htmlStr += '<label class="control-label">商品条码：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span11" type="text" id="input-barcode" value="">';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '<div class="span6">';
	htmlStr += '<label class="control-label">是否上架：</label><div class="controls">';
	htmlStr += '<label class="inline"><input type="radio" name="merchandise.closed" value="1" checked />是</label>&nbsp;&nbsp;<label class="inline"><input type="radio" name="merchandise.closed" value="0"/>否</label>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';

	htmlStr += '<div class="control-group">';
	htmlStr += '<div class="span6" id="control-group-merchandiseName">';
	htmlStr += '<label class="control-label"><i class="required">*</i>商品名称：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span11" type="text" id="input-merchandiseName" value="" placeholder="商品名称不要超过40个字"> ';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '<div class="span6" id="control-group-brief">';
	htmlStr += '<label class="control-label">商品简介：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span11" type="text" id="input-brief" value="" placeholder="商品简介不要超过50个字">';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';

	htmlStr += '<div class="control-group zindex">';
	htmlStr += '<div class="span6" id="control-group-merTypeListSystemInput">';
	htmlStr += '<label class="control-label"><i class="required">*</i>商品分类：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input id="merTypeListSystemInput" class="span11 alert_w alert_class" type="text" readonly value="" placeholder="商品在系统中的分类，用于商品分类搜索" />';
	htmlStr += '<div class="span11 alert_list">';
	htmlStr += '<ul id="merTypeListSystemNewPage">';
	htmlStr += '</ul>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '<div class="span6">';
	htmlStr += '<label class="control-label">商家自定义分类：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span11 alert_w alert_class2" type="text" readonly  placeholder="店内商品分类"/>';
	htmlStr += '<div class="span11 alert_list2">';
	htmlStr += '<ul id="merTypeListPNewPage">';
	htmlStr += '</ul>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';

	htmlStr += '<div class="control-group">';
	htmlStr += '<div class="span6" id="control-group-salePrice">';
	htmlStr += '<label class="control-label"><i class="required">*</i>销售单价：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<p class="input-append"><input class="span11" type="text" id="input-salePrice" value=""><span class="add-on">元</span></p>';
	htmlStr += '</div>           ';
	htmlStr += '<pre class="help-div offset3" style="color:#888; background:none;border:0px;padding:0px;">';
	htmlStr += '<p>各种价格示意图：<a class="help-img-a" href="javascript:void(0)">鼠标进入查看参考图<span class="help-img"><img src="img/help-img.png"/></span></a></p>';
	htmlStr += '</pre> ';
	htmlStr += '</div>';
	htmlStr += '<div class="span6" id="control-group-mktprice">';
	htmlStr += '<label class="control-label">市场价格：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<p class="input-append"><input class="span11" type="text" id="input-mktprice" value=""><span class="add-on">元</span></p>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';

	htmlStr += '<div class="control-group">';
	htmlStr += '<div class="span6" id="control-group-inventory">';
	htmlStr += '<label class="control-label"><i class="required">*</i>库存数量：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span3" type="text" id="input-inventory" value="999"><input class="span2" type="text" id="input-unitName" value="个" placeholder="单位" />';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '<div class="span6" id="control-group-costPrice">';
	htmlStr += '<label class="control-label">成本单价：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<p class="input-append"><input class="span11" type="text" id="input-costPrice" value=""><span class="add-on">元</span></p>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';

	htmlStr += '<div class="control-group">';
	htmlStr += '<div class="span6" id="control-group-inventoryWarn">';
	htmlStr += '<label class="control-label">缺货提醒：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span3" type="text" id="input-inventoryWarn" value="5" placeholder="库存量等于或低于该值，则会在显示在缺货商品中"> ';
	htmlStr += '<span class="help-inline">库存量等于或低于该值，则会在显示在缺货商品中</span>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '<div class="span6" id="control-group-seoWeight">';
	htmlStr += '<label class="control-label">排序优先度：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<label class="inline"><input type="radio" name="merchandise.seoWeight" value="0" checked />普通</label>&nbsp;&nbsp;<label class="inline"><input type="radio" name="merchandise.seoWeight" value="1" />优先</label>&nbsp;&nbsp;<label class="inline"><input type="radio" name="merchandise.seoWeight" value="2" />最优</label>&nbsp;&nbsp;';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';

	htmlStr += '<div class="control-group">';
	htmlStr += '<div class="span6">';
	htmlStr += '<label class="control-label">生产厂家：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input  class="span11"  id="input-vendorName" type="text"  value="" />   ';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '<div class="span6">';
	htmlStr += '<label class="control-label">是否推荐：</label><div class="controls">';
	htmlStr += '<label class="inline"><input type="radio" name="merchandise.recommended" value="1"/>是</label>&nbsp;&nbsp;<label class="inline"><input type="radio" name="merchandise.recommended" value="0" checked />否</label>';
	htmlStr += '</div>                          ';
	htmlStr += '</div>';
	htmlStr += '</div>';
	
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">商品图片：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<div class="upload_box">';
	htmlStr += '<span id="uploadMerchandise"></span>';
	htmlStr += '<div style="display:none;" class="progress progress-success progress-striped ">';
	htmlStr += '<div class="bar" style="width: 0%;" id="prencentIcon"></div>  ';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '<div class="picture">';
	htmlStr += '<div class="default_pic"><p><img id="defImgPath" src="'
			+ picDefault + '"></p><div class="setDefault">默认图片</div></div>';
	htmlStr += '<div class="pic_btn_left" style="display: block;"></div>';
	htmlStr += '<div class="product_pic" id="product_pic" style="width: 504px;">      ';
	htmlStr += '<ul style="width: 840px;" id="goodsPicList" >';
	htmlStr += '</ul>';
	htmlStr += '</div>';
	htmlStr += '<div class="pic_btn_right" style="display: block;"></div>';
	htmlStr += '</div>';
	htmlStr += '<span class="help-block">说明：最多上传6张图片，图片尺寸为宽1080*高540 ，图片大小不能超过1MB，图片格式为jpg、png</span>';
	htmlStr += '</div>     ';
	htmlStr += '</div>';

	htmlStr += '<div class="control-group" id="control-group-merDetail">';
	htmlStr += '<label class="control-label">商品详情：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<textarea name="content" id="input-merDetail" style="width:800px;height:400px;"></textarea>';
	htmlStr += '</div>                   ';
	htmlStr += '</div>';

	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div> ';
	htmlStr += '</div>';
	htmlStr += '</div> ';
	htmlStr += '</div> ';
	
//	htmlStr += '<div class="form-actions">';
//	htmlStr += '<button class="btn btn-primary" type="button" onclick="$ddf_merchandise.saveAndNew()" >保存</button>';
//	htmlStr += ' <button class="btn btn-info" type="button" onClick=$ddf_merchandise.showDiv("content0")>返回</button>      ';
//	htmlStr += '</div>  ';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div> ';
	htmlStr += '</div>';
	htmlStr += '</div> ';
	htmlStr += '</div> ';
	
	showDiv("content1");
	
	$("#content1").html(htmlStr);
	
		
	base.setRadioStyles();
	
	getErpMerchandiseTypesListSystem("", "NewPage");
	getErpMerchandiseTypesList("newMer", "NewPage");
	$(".swfupload").addClass("btn");
	upload.setCurrentMerCount(0);// 重置当前上传图片数量
	upload.ddf_upload_merchandiseImg("uploadMerchandise", "/shop/" + shopId
			+ "/goods", "$ddf_merchandise.uploadCallBack");

	$.each('#input-merDetail', function() {

		// 加载编辑器
		LoadEditor();

	});

	$("#input-merchandiseName").change(function() {
		
		var merchandiseName=$("#input-merchandiseName").val();
		
		if(isNull(merchandiseName)){
			base.addErrorMessage_block("control-group-merchandiseName","input-merchandiseName","商品名称非法");
		}else if(isLength(merchandiseName,80)){
			
			base.addErrorMessage_block("control-group-merchandiseName","input-merchandiseName","商品名称不要超过40个字");
		}else{
			base.clearErrorMessage_block("control-group-merchandiseName");
		}
		
	});
	
	$("#input-brief").change(function() {
		
		var brief=$("#input-brief").val();
		
		if(isLength(brief,100)){
			
			base.addErrorMessage_block("control-group-brief","input-brief","商品简介不要超过50个字");
		}else{
		
			base.clearErrorMessage_block("control-group-brief");
		}
		
	});
	
	$("#input-mktprice").change(function() {
		
		var mktprice=$("#input-mktprice").val();
		
		if(!isNull(mktprice) && !isMerPrice(mktprice)){
			base.addErrorMessage_block("control-group-mktprice","input-mktprice","市场价格非法,价格格式：不大于10位数字,只能输入整数,或带两位小数的数字");
		}else{
			base.clearErrorMessage_block("control-group-mktprice");
		}
		
	});
	
	$("#input-costPrice").change(function() {
		
		var costPrice=$("#input-costPrice").val();
		
		if(!isNull(costPrice) && !isMerPrice(costPrice)){
			base.addErrorMessage_block("control-group-costPrice","input-costPrice","成本单价非法,价格格式：不大于10位数字,只能输入整数,或带两位小数的数字");
		}else{
			base.clearErrorMessage_block("control-group-costPrice");
		}
		
	});
	
	$("#input-salePrice").change(function() {
		
		var salePrice=$("#input-salePrice").val();
		
		if(isNull(salePrice) || !isMerPrice(salePrice)){
			base.addErrorMessage_block("control-group-salePrice","input-salePrice","销售单价非法,价格格式：不大于10位数字,只能输入整数,或带两位小数的数字");
		}else{
			base.clearErrorMessage_block("control-group-salePrice");
		}
		
	});
	
	$("#input-inventory").change(function() {
		base.clearErrorMessage_block("control-group-inventory");
		var inventory=$("#input-inventory").val();
		var unitName=$("#input-unitName").val();
		if(isNull(inventory) || !isPositiveInteger(inventory)){
			base.addErrorMessage_block("control-group-inventory","input-inventory","库存数量非法");
		}else if(isLength(unitName,10)){
			base.addErrorMessage_block("control-group-inventory","input-inventory","单位不要超过5个字");
		}
			
	});
		
	$("#input-unitName").change(function() {
		base.clearErrorMessage_block("control-group-inventory");
		var inventory=$("#input-inventory").val();
		var unitName=$("#input-unitName").val();
		if(isLength(unitName,10)){
			base.addErrorMessage_block("control-group-inventory","input-inventory","单位不要超过5个字");
		}else if(isNull(inventory) || !isPositiveInteger(inventory)){
			base.addErrorMessage_block("control-group-inventory","input-inventory","库存数量非法");
		}
		
	});
	
	$("#input-inventoryWarn").change(function() {
		
		var inventoryWarn=$("#input-inventoryWarn").val();
		
		if(!isNull(inventoryWarn) && !isPositiveInteger(inventoryWarn)){
			base.addErrorMessage_block("control-group-inventoryWarn","input-inventoryWarn","缺货提醒输入非法");
		}else{
			base.clearErrorMessage_block("control-group-inventoryWarn");
		}
		
	});
	 
	
	$("#input-ddpScore").change(function() {
		
		var ddpScore=$("#input-ddpScore").val();
		
		if(!isNull(ddpScore) && !isPositiveInteger(ddpScore)){
			base.addErrorMessage_block("control-group-ddpScore","input-ddpScore","币数非法");
		}else{
			base.clearErrorMessage_block("control-group-ddpScore");
		}
		
	});

	$("#input-barcode").change(function() {
		exports.loadBarcode();
	});
	
//	// 绑定事件
//	$("#input-barcode").focus(function() {
//	});

	// 获取焦点
	$("#input-barcode").focus();// 获取焦点
	$("#input-barcode").bind("keydown", function(event) {
		var keycode = event.keyCode;
		if (keycode == 13) {
//			$("#input-barcode").unbind();
//			exports.loadBarcode();
			$("#input-barcode").blur();
		}
	});

	$("#input-salePrice").bind("keydown", function(event) {
		var keycode = event.keyCode;
		if (keycode == 13) {
			// alert("OK");
			exports.saveAndNew();// 保存并刷新页面
		}
	});
	
	
	base.cancelLoading();
}

exports.loadBarcode=function(){
	var barcode=$("#input-barcode").val();
	
	if(!isEnglishNO(barcode)){
		base.addErrorMessage_block("control-group-barcode","input-barcode","条形码非法");
	}else{
		if(!isNull(barcode)){
			if(isNull(shopId)){
				base.tips_error("请先选择一个商家");
				return;
			}
			var params={
					"shopId":shopId,
					"barcode":barcode
			}
			base.showLoading();
			eval(Wind.compile("async",function(){
				var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.merchandise.checkBarcode,params));
				checkOrLoadBarcodeCallBack(data);
			}))().start();
		}
		
		base.clearErrorMessage_block("control-group-barcode");
	}
}

function checkOrLoadBarcodeCallBack(data){
	if(data["code"]=="1"){
		goodsPicArray=new Array();
//		$("#input-merchandiseName").val(data["NAME"]);
//		$("#input-brief").val(data["BRIEF"]);
//		$("#input-mktprice").val(data["MKTPRICE"]);
//		$("#input-unitName").val(data["UNIT_NAME"]);
//		$("#input-vendorName").val(data["VENDOR_NAME"]);
//		getErpMerchandiseTypesListSystem(data["MERCHANDISE_TYPE_ID"]);
		if (data["nullErpBarcode"] == "nullErpBarcode") {
			$("#input-merchandiseName").val("");
			$("#input-brief").val("");
			$("#input-mktprice").val("");
			$("#input-unitName").val("件");
			$("#input-vendorName").val("");

			sysType = "";
			$("#merTypeListSystemInput").val("");

			perType = "";
			$("#merTypeListInput").val("");

			$("#goodsPicList").html("");
			$("#defImgPath").attr("src", picDefault);

			// base.tips_error("此条形码不存在");
		} else{
			$("#input-merchandiseName").val(data["NAME"]);
			$("#input-brief").val(data["BRIEF"]);
			$("#input-mktprice").val(data["MKTPRICE"]);
			$("#input-unitName").val(data["UNIT_NAME"]);
			$("#input-vendorName").val(data["VENDOR_NAME"]);
			getErpMerchandiseTypesListSystem(data["MERCHANDISE_TYPE_ID"],
					"NewPage");
	
			$("#goodsPicList").html("");
			$("#defImgPath").attr("src", picDefault);
			for (var i = 0; i < data["barcodePicList"].length; i++) {
				if (data["barcodePicList"][i]["def"] == 1) {
					defImgPath = data["barcodePicList"][i]["imageUrl"];
					$("#defImgPath").attr("src", fileOpenUrl + defImgPath);
				}
				setGoodsPic("edit", data["barcodePicList"][i]["imageId"],
						data["barcodePicList"][i]["imageUrl"]);
			}
			$("#input-salePrice").focus();
		}
		
	}else{
		base.tips_error(data["message"]);
	}
	
//	$("#input-barcode").unbind();
//	// 绑定事件
//	$("#input-barcode").change(function() {
//		exports.loadBarcode();
//	});
//	// 获取焦点
//	$("#input-barcode").bind("keydown", function(event) {
//		var keycode = event.keyCode;
//		if (keycode == 13) {
//			$("#input-barcode").unbind();
//			exports.loadBarcode();
//		}
//	});
	
	base.cancelLoading();
}


//点击 “保存并继续添加” 按钮
exports.saveAndNew = function() {
	exports.saveNext("toNew");
}

exports.saveNext=function(newPage){
	var barcode=$("#input-barcode").val();
	if(!isEnglishNO(barcode)){
		base.addErrorMessage_block("control-group-barcode","input-barcode","条形码非法");
		return;
	}else if(isNull(barcode)){
		exports.saveandNext(newPage);
	}else{
		var params={
				"barcode":barcode
		}
		eval(Wind.compile("async",function(){
			var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.merchandise.checkBarcode,params));
			checkBarcodeCallBack(data, newPage);
		}))().start();
	}
	
}

function checkBarcodeCallBack(data, newPage){
	if(data["code"]=="1"){
		exports.saveandNext(newPage);
	}else{
		base.tips_error(data["message"]);
	}
}

exports.saveandNext=function(newPage){
	var barcode=$("#input-barcode").val();
	var merchandiseName=$("#input-merchandiseName").val();;
	var brief=$("#input-brief").val();
	
	var costPrice=$("#input-costPrice").val();
	var mktprice=$("#input-mktprice").val();  
	var salePrice=$("#input-salePrice").val();
	var inventory=$("#input-inventory").val();
	var unitName=$("#input-unitName").val();
	var vendorName=$("#input-vendorName").val();
	var closed=$('input[name="merchandise.closed"]:checked').val();
	var recommended=$('input[name="merchandise.recommended"]:checked').val();
	var inventoryWarn=$("#input-inventoryWarn").val();
	var seoWeight=$('input[name="merchandise.seoWeight"]:checked').val();
	var memo = kindEditor.html();
	if(!isEnglishNO(barcode)){
		base.addErrorMessage_block("control-group-barcode","input-barcode","条形码非法");
		return;
	}
	
	if(isNull(merchandiseName)){
		base.addErrorMessage_block("control-group-merchandiseName","input-merchandiseName","商品名称非法");
		return;
	}
	if(isLength(merchandiseName,80)){

		base.addErrorMessage_block("control-group-merchandiseName","input-merchandiseName","商品名称不要超过40个字");
		return;
	}

	if(isLength(brief,100)){

		base.addErrorMessage_block("control-group-brief","input-brief","商品简介不要超过50个字");
		return;
	}

	if(isNull(sysType)){
		base.tips_error("请选择商品分类");
		return;
	}

	if(!isMerPrice(costPrice)){
		base.addErrorMessage_block("control-group-costPrice","input-costPrice","成本单价非法,只能输入整数,或带两位小数的数字");
		return;
	}

	if(!isMerPrice(mktprice)){
		base.addErrorMessage_block("control-group-mktprice","input-mktprice","市场价格非法,只能输入整数,或带两位小数的数字");
		return;
	}

	if(isNull(salePrice) || !isMerPrice(salePrice)){
		base.addErrorMessage_block("control-group-salePrice","input-salePrice","销售单价非法,只能输入整数,或带两位小数的数字");
		return;
	}

	if(isNull(inventory) || !isPositiveInteger(inventory)){
		base.addErrorMessage_block("control-group-inventory","input-inventory","库存数量非法");
		return;
	}
	
	if(!isNull(inventoryWarn) && !isPositiveInteger(inventoryWarn)){
		base.addErrorMessage_block("control-group-inventoryWarn","input-inventoryWarn","缺货提醒输入非法");
		return;
	}
//	if(!("" == seoWeight || null == seoWeight)){
//		if(!isInteger(seoWeight)){
//			addErrorMessage("control-group-seoWeight","input-seoWeight","商品权重应为整数");
//			return;
//		}
//	}else{
//		base.clearErrorMessage("control-group-seoWeight");
//	}
	params={
			"barcode":barcode,
			"merchandiseName":merchandiseName,
			"brief":brief,
			"merchandiseTypeId":sysType,
			"perType":perType,
			"unitName":unitName,
			"inventory":inventory,
			"costPrice":costPrice,
			"mktprice":mktprice,
			"salePrice":salePrice,
			"closed":closed,
			"recommended":recommended,
			"inventoryWarn":inventoryWarn,
			"vendorName":vendorName,
			"seoWeight":seoWeight,
			"detail" : memo,
			"defImgPath":defImgPath
	};
	
	for (var i = 0; i < goodsPicArray.length; i++) {

		if (isNull(defImgPath)) {

			defImgPath = goodsPicArray[0];

			params["defImgPath"] = defImgPath;
		}

		params["goodsPicList[" + i + "].imageUrl"] = goodsPicArray[i];

	}

	base.showLoading();
	eval(
			Wind.compile("async", function() {
				var data = $await(wind_async.DDF_AsyncRequest("POST",
						ddf.merchandise.addGoodsInfo, params));
				saveandNextCallBack(data,newPage);
			}))().start();
	
}

function saveandNextCallBack(data,newPage) {
	base.cancelLoading();
	if (data["code"] == "1") {
		base.tips("添加商品成功！");
		if (newPage == "toNew") {// “toNew”：点击了“保存并继续添加”按钮
			openAddMerchandise();// 重新打开“添加商品页面”
		} else {
			// 跳转回列表
			showDiv("content0");
			sort="1";
			$("#searchMerBtn").click();// 刷新列表
		}
	} else {
		base.tips_error(data["message"]);
	}

}

exports.saveNextPage=function(){
	history.addHis(this,arguments);//增加历史
	var htmlStr="";
	
	htmlStr += '<div id="content-header">';
	htmlStr += '<div id="breadcrumb"> <a href=javascript:load("'+ddf.index.index_js+'",1,"$ddf_index.loadIndex","") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href=javascript:$ddf_merchandise.showDiv("content0")>商品管理</a><a href="javascript:void(0)" class="current">添加商品</a></div>';
	htmlStr += '</div>    ';

	htmlStr += '<div class="container-fluid">';
	htmlStr += '<div class="row-fluid">';
	htmlStr += '<div class="span12">    	';
	htmlStr += '<div id="alert-tips1" ></div>';
	htmlStr +='<div id="errorMessage-addMer" style="display:none" class="alert alert-error alert-block">';
	htmlStr +='<a class="close" href="#" data-dismiss="alert">×</a>';
	htmlStr +='<h4 class="alert-heading">Error!</h4>';
	htmlStr +='You are not looking too good. Nulla vitae elit libero, a pharetra augue. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.';
	htmlStr +='</div>  ';
	
	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title"> <span class="icon"><i class="icon-th"></i></span>';
	htmlStr += '<h5>添加商品</h5>';
	htmlStr += '</div>';
	htmlStr += '<div class="widget-content nopadding">';
	htmlStr += '<div class="form-horizontal">	';
	
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">商品图片：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<div class="upload_box">';
	htmlStr += '<span id="uploadMerchandise"></span>';
	htmlStr += '<div style="display:none;" class="progress progress-success progress-striped ">';
	htmlStr += '<div class="bar" style="width: 0%;" id="prencentIcon"></div>  ';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '<div class="picture">';
	htmlStr += '<div class="default_pic"><p><img id="defImgPath" src="../img/pic_bg.png"></p><div class="setDefault">默认图片</div></div>';
	htmlStr += '<div class="pic_btn_left" style="display: block;"></div>';
	htmlStr += '<div class="product_pic" id="product_pic" style="width: 504px;">      ';
	htmlStr += '<ul style="width: 840px;" id="goodsPicList" >';
	htmlStr += '</ul>';
	htmlStr += '</div>';
	htmlStr += '<div class="pic_btn_right" style="display: block;"></div>';
	htmlStr += '</div>';
	htmlStr += '<span class="help-block">说明：图片尺寸为宽1080*高540 ，图片大小不能超过1MB，图片格式为jpg、png</span>';
	htmlStr += '</div>     ';
	htmlStr += '</div>';
	
	htmlStr += '<div class="control-group" id="control-group-merDetail">';
	htmlStr += '<label class="control-label">商品详情：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<textarea name="content" id="input-merDetail" style="width:800px;height:400px;"></textarea>';
	htmlStr += '</div>                   ';
	htmlStr += '</div>';
	

	htmlStr += '<div class="form-actions">';
	htmlStr += '<button class="btn btn-primary" type="button" onclick=$ddf_merchandise.saveFinish() >保存</button>';
	htmlStr += ' <button class="btn btn-info" type="button" onClick=$ddf_merchandise.showDiv("content1")>返回</button>      ';
	htmlStr += '</div>  ';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div> ';
	htmlStr += '</div>';
	htmlStr += '</div> ';
	htmlStr += '</div> ';
	
	showDiv("content19");
	$("#content20").html("");
	$("#content19").html(htmlStr);
	
	picRoll();
	
	$(".swfupload").addClass("btn");
	upload.ddf_upload_merchandiseImg("uploadMerchandise","/shop/"+shopId+"/goods","$ddf_merchandise.uploadCallBack");
	
	$.each('#input-merDetail', function() {
		 
        // 加载编辑器
        LoadEditor();

    });
	
};


exports.saveFinish=function(){
	var memo=kindEditor.html();
	var params={
			
			"barcode":merchandise["barcode"],
			"merchandiseName":merchandise["merchandiseName"],
			"brief":merchandise["brief"],
			"merchandiseTypeId":merchandise["merchandiseTypeId"],
			"perType":merchandise["perType"],
			"unitName":merchandise["unitName"],
			"inventory":merchandise["inventory"],
			"costPrice":merchandise["costPrice"],
			"mktprice":merchandise["mktprice"],
			"salePrice":merchandise["salePrice"],
			"vendorName":merchandise["vendorName"],
			"closed":merchandise["closed"],
			"recommended":merchandise["recommended"],
			"inventoryWarn":merchandise["inventoryWarn"],
			"detail":memo,
			"defImgPath":defImgPath,
			"seoWeight":merchandise["seoWeight"]
			
	};
	
	
	for(var i=0;i<goodsPicArray.length;i++){
		
		if(isNull(defImgPath)){
			
			defImgPath=goodsPicArray[0];

			params["defImgPath"]=defImgPath;
		}
		
		params["goodsPicList["+i+"].imageUrl"]=goodsPicArray[i];
		
	}
	
	
	base.showLoading();
	eval(Wind.compile("async",function(){
		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.merchandise.addGoodsInfo,params));
		addMerchandiseCallBack(data);
	}))().start();
}

/**
 * 上传图片回调函数
 */
exports.uploadCallBack=function(dataObj){
	
	var dataPath = "";
	if(dataObj.code == "1"){
		for(var i=0;i<dataObj.files.length;i++){
			if(dataObj.files[i].repCode=="1"){
				dataPath = dataObj.files[i].path;
				upload.setCurrentMerCount(upload.getCurrentMerCount()+1);// 设置上传图片数量
				setGoodsPic("add","",dataPath);
			}else{
				base.tips_error("上传失败!");
			}
		}
	}
	
	base.cancelLoading();
}

/**
 * 上传图片回调函数
 */
exports.uploadDetailCallBack=function(dataObj){
	var dataPath = "";
	if(dataObj.code == "1"){
		for(var i=0;i<dataObj.files.length;i++){
			if(dataObj.files[i].repCode=="1"){
				dataPath = dataObj.files[i].path;
				 //$(".ke-edit-iframe").contents().find("body").focus();
				// editor.html('<img src="'+fileOpenUrl+dataPath+'" />');
				kindEditor.insertHtml('<img src="'+fileOpenUrl+dataPath+'" />');

				//$(".ke-edit-iframe").contents().find("body").append('<img src="'+fileOpenUrl+dataPath+'" />');
			}else{
				base.tips_error("上传失败!");
			}
		}
	}
	
	
	base.cancelLoading();
}


/**
 * 加载编辑器
 */
var kindEditor;
function LoadEditor(data) {
	var _kindEditor=KindEditor.create('#input-merDetail', {
	    //uploadJson : fileUploadUrl+"?path=/shop/"+shopId+"/goods&rename=true",
        //fileManagerJson :"http://localhost:8080/admin/admin/file_manager_json.jsp",
		items:[
		        'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
		        'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
		        'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
		        'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
		        'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
		        'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 
		        'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
		        'anchor', 'link', 'unlink', '|', 'about'
		],
        allowFileManager: true,
        autoHeightMode: true,
        pasteType : 2,

        afterCreate: function() {
        	
        	$("#control-group-merDetail .controls .ke-toolbar").after('<div style="display:block;" class="ke-toolbar" unselectable="on"><span id="uploadMerchandiseDetail"></span></div>');
        	
        	upload.ddf_upload("uploadMerchandiseDetail","/shop/"+shopId+"/goods","$ddf_merchandise.uploadDetailCallBack");

        	kindEditor=this;

	       	 if(typeof data!="undefined"){
	           	 kindEditor.html(data);
	       	 }
        },
        afterChange: function() {
        	
            this.sync();
        },
        afterBlur: function() {
        	
            this.sync();
        }
    });
		
}



/**
 * 添加商品信息_回调函数
 */
function addMerchandiseCallBack(data){
	
	
	
/*	$("#errorMessage-addMer").css("display","block");
	
	if(data["code"]==1){
		
		$("#errorMessage-addMer").html("添加商品成功");
		
	}else{
		
		$("#errorMessage-addMer").html(data["message"]);
		
	}*/
	
	if(data["code"]==1){
		
		//$("#errorMessage-addUser").html("增加用户成功");
//		back("content1","content0");
		showDiv("content0");
		$("#searchMerBtn").click();// 刷新列表
		base.tips("添加商品成功");
		
		getMerchandiseList(1,10,keywordsType,keywords,merStatus);

	}else{
		
		//$("#errorMessage-addUser").html(data["message"]);
		
		base.tips_error(data["message"]);
		
    }
	merchandise={};//清空属性
	base.cancelLoading();
	
}

/**
 * 加载商品详情并编辑
 */
function loadMerchandiseDetail(_merchandiseId){
	history.addHis(this,arguments);//增加历史
	merchandiseId=_merchandiseId;
	sysType="",perType="";
	
	goodsPicArray = new Array();//清除图片变量
		
	var htmlStr="";
	
	htmlStr += '<div id="content-header">';
	htmlStr += '<div id="breadcrumb"> <a href=javascript:load("'+ddf.index.index_js+'",1,"$ddf_index.loadIndex","") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href=javascript:$ddf_merchandise.showDiv("content0")>商品管理</a><a href="javascript:void(0)" class="current">修改商品信息</a></div>';
	htmlStr += '</div>    ';

	htmlStr += '<div class="container-fluid">';
	htmlStr += '<div class="row-fluid">';
	htmlStr += '<div class="span12">    	';
	htmlStr += '<div id="alert-tips2" ></div>';
	htmlStr +='<div id="errorMessage-updateMer" style="display:none" class="alert alert-error alert-block">';
	htmlStr +='<a class="close" href="#" data-dismiss="alert">×</a>';
	htmlStr +='<h4 class="alert-heading">Error!</h4>';
	htmlStr +='You are not looking too good. Nulla vitae elit libero, a pharetra augue. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.';
	htmlStr +='</div>  ';
	
	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title"> <span class="icon"><i class="icon-th"></i></span>';
	htmlStr += '<h5>商品信息</h5>';
	htmlStr += '</div>';
	htmlStr += '<div class="widget-content nopadding">';
	htmlStr += '<div class="form-horizontal">	';
	
	htmlStr += '<div class="control-group">';
	htmlStr += '<div class="span6" id="control-group-barcode">';
	htmlStr += '<label class="control-label">商品条码：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span11" type="text" id="input-barcode" value="">';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '<div class="span6">';
	htmlStr += '<label class="control-label">是否上架：</label><div class="controls">';
	htmlStr += '<label class="inline"><input type="radio" name="merchandise.closed" value="1" checked />是</label>&nbsp;&nbsp;<label class="inline"><input type="radio" name="merchandise.closed" value="0"/>否</label>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';

	htmlStr += '<div class="control-group">';
	htmlStr += '<div class="span6" id="control-group-merchandiseName">';
	htmlStr += '<label class="control-label"><i class="required">*</i>商品名称：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span11" type="text" id="input-merchandiseName" value="" placeholder="商品名称不要超过40个字"> ';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '<div class="span6" id="control-group-brief">';
	htmlStr += '<label class="control-label">商品简介：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span11" type="text" id="input-brief" value="" placeholder="商品简介不要超过50个字">';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';

	htmlStr += '<div class="control-group zindex">';
	htmlStr += '<div class="span6" id="control-group-merTypeListSystemInput">';
	htmlStr += '<label class="control-label"><i class="required">*</i>商品分类：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input id="merTypeListSystemInput" class="span11 alert_w alert_class" type="text" readonly value="" placeholder="商品在系统中的分类，用于商品分类搜索" />';
	htmlStr += '<div class="span11 alert_list">';
	htmlStr += '<ul id="merTypeListSystemNewPage">';
	htmlStr += '</ul>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '<div class="span6">';
	htmlStr += '<label class="control-label">商家自定义分类：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span11 alert_w alert_class2" type="text" readonly  placeholder="店内商品分类"/>';
	htmlStr += '<div class="span11 alert_list2">';
	htmlStr += '<ul id="merTypeListPNewPage">';
	htmlStr += '</ul>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';

	htmlStr += '<div class="control-group">';
	htmlStr += '<div class="span6" id="control-group-salePrice">';
	htmlStr += '<label class="control-label"><i class="required">*</i>销售单价：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<p class="input-append"><input class="span11" type="text" id="input-salePrice" value=""><span class="add-on">元</span></p>';
	htmlStr += '</div>           ';
	htmlStr += '<pre class="help-div offset3" style="color:#888; background:none;border:0px;padding:0px;">';
	htmlStr += '<p>各种价格示意图：<a class="help-img-a" href="javascript:void(0)">鼠标进入查看参考图<span class="help-img"><img src="img/help-img.png"/></span></a></p>';
	htmlStr += '</pre> ';
	htmlStr += '</div>';
	htmlStr += '<div class="span6" id="control-group-mktprice">';
	htmlStr += '<label class="control-label">市场价格：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<p class="input-append"><input class="span11" type="text" id="input-mktprice" value=""><span class="add-on">元</span></p>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';

	htmlStr += '<div class="control-group">';
	htmlStr += '<div class="span6" id="control-group-inventory">';
	htmlStr += '<label class="control-label"><i class="required">*</i>库存数量：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span3" type="text" id="input-inventory" value="999"><input class="span2" type="text" id="input-unitName" value="个" placeholder="单位" />';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '<div class="span6" id="control-group-costPrice">';
	htmlStr += '<label class="control-label">成本单价：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<p class="input-append"><input class="span11" type="text" id="input-costPrice" value=""><span class="add-on">元</span></p>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';

	htmlStr += '<div class="control-group">';
	htmlStr += '<div class="span6" id="control-group-inventoryWarn">';
	htmlStr += '<label class="control-label">缺货提醒：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span3" type="text" id="input-inventoryWarn" value="5" placeholder="库存量等于或低于该值，则会在显示在缺货商品中"> ';
	htmlStr += '<span class="help-inline">库存量等于或低于该值，则会在显示在缺货商品中</span>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '<div class="span6" id="control-group-seoWeight">';
	htmlStr += '<label class="control-label">排序优先度：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<label class="inline"><input type="radio" name="merchandise.seoWeight" value="0" checked />普通</label>&nbsp;&nbsp;<label class="inline"><input type="radio" name="merchandise.seoWeight" value="1" />优先</label>&nbsp;&nbsp;<label class="inline"><input type="radio" name="merchandise.seoWeight" value="2" />最优</label>&nbsp;&nbsp;';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';

	htmlStr += '<div class="control-group">';
	htmlStr += '<div class="span6">';
	htmlStr += '<label class="control-label">生产厂家：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input  class="span11"  id="input-vendorName" type="text"  value="" />   ';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '<div class="span6">';
	htmlStr += '<label class="control-label">是否推荐：</label><div class="controls">';
	htmlStr += '<label class="inline"><input type="radio" name="merchandise.recommended" value="1" checked />是</label>&nbsp;&nbsp;<label class="inline"><input type="radio" name="merchandise.recommended" value="0"/>否</label>';
	htmlStr += '</div>                          ';
	htmlStr += '</div>';
	htmlStr += '</div>';
	
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">商品二维码：</label>';
	htmlStr += '<div class="controls"><div class="logoSize"><img id="merCode" />';
	htmlStr += '<iframe   width=0   height=0   frameborder=0   name=hrong   style="display:   none"></iframe> ';
	htmlStr += '<div style="padding-top:10px;"><button class="btn btn-primary" type="button" onclick=javascript:$ddf_merchandise.showDownMerCode()>下载二维码</button>';
	htmlStr += '</div></div></div></div>       ';
	
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">商品图片：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<div class="upload_box">';
	htmlStr += '<span id="uploadMerchandise"></span>';
	htmlStr += '<div style="display:none;" class="progress progress-success progress-striped ">';
	htmlStr += '<div class="bar" style="width: 0%;" id="prencentIcon"></div>  ';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '<div class="picture">';
	htmlStr += '<div class="default_pic"><p><img id="defImgPath" src="'
			+ picDefault + '"></p><div class="setDefault">默认图片</div></div>';
	htmlStr += '<div class="pic_btn_left" style="display: block;"></div>';
	htmlStr += '<div class="product_pic" id="product_pic" style="width: 504px;">      ';
	htmlStr += '<ul style="width: 840px;" id="goodsPicList" >';
	htmlStr += '</ul>';
	htmlStr += '</div>';
	htmlStr += '<div class="pic_btn_right" style="display: block;"></div>';
	htmlStr += '</div>';
	htmlStr += '<span class="help-block">说明：最多上传6张图片，图片尺寸为宽1080*高540 ，图片大小不能超过1MB，图片格式为jpg、png</span>';
	htmlStr += '</div>     ';
	htmlStr += '</div>';

	htmlStr += '<div class="control-group" id="control-group-merDetail">';
	htmlStr += '<label class="control-label">商品详情：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<textarea name="content" id="input-merDetail" style="width:800px;height:400px;"></textarea>';
	htmlStr += '</div>                   ';
	htmlStr += '</div>';
	
	if(EDITFlag){
		htmlStr += '<button class="btn btn-primary" type="button" onclick=$ddf_merchandise.updateNext() >保存</button>';
	}
	htmlStr += ' <button class="btn btn-info" type="button" onClick=$ddf_merchandise.showDiv("content0")>返回</button>      ';
	htmlStr += '</div>';
	htmlStr += '</div>';

	htmlStr += '</div> ';
	htmlStr += '</div>';
	htmlStr += '</div> ';
	htmlStr += '</div> ';
	htmlStr += '</div> ';
	

	$("#content1").html("");
	
	showDiv("content2");
	
	$("#content2").html(htmlStr);
	
	$("#input-barcode").change(function() {
			
			var barcode=$("#input-barcode").val();
			
			if(!isEnglishNO(barcode)){
				base.addErrorMessage_block("control-group-barcode","input-barcode","条形码非法");
			}else{
				base.clearErrorMessage_block("control-group-barcode");
			}
			
		});
	
	$("#input-merchandiseName").change(function() {
		
		var merchandiseName=$("#input-merchandiseName").val();
		
		if(isNull(merchandiseName)){
			base.addErrorMessage_block("control-group-merchandiseName","input-merchandiseName","商品名称非法");
		}else if(isLength(merchandiseName,80)){
			
			base.addErrorMessage_block("control-group-merchandiseName","input-merchandiseName","商品名称不要超过40个字");
		}else{
			base.clearErrorMessage_block("control-group-merchandiseName");
		}
		
	});
	
	$("#input-brief").change(function() {
		
		var brief=$("#input-brief").val();
		
		if(isLength(brief,100)){
			
			base.addErrorMessage_block("control-group-brief","input-brief","商品简介不要超过50个字");
		}else{
		
			base.clearErrorMessage_block("control-group-brief");
		}
		
	});
	
	$("#input-mktprice").change(function() {
		
		var mktprice=$("#input-mktprice").val();
		
		if(!isMerPrice(mktprice)){
			base.addErrorMessage_block("control-group-mktprice","input-mktprice","市场价格非法,只能输入整数,或带两位小数的数字");
		}else{
			base.clearErrorMessage_block("control-group-mktprice");
		}
		
	});
	
	$("#input-costPrice").change(function() {
		
		var costPrice=$("#input-costPrice").val();
		
		if(!isMerPrice(costPrice)){
			base.addErrorMessage_block("control-group-costPrice","input-costPrice","成本单价非法,只能输入整数,或带两位小数的数字");
		}else{
			base.clearErrorMessage_block("control-group-costPrice");
		}
		
	});
	
	$("#input-salePrice").change(function() {
		
		var salePrice=$("#input-salePrice").val();
		
		if(isNull(salePrice) || !isMerPrice(salePrice)){
			base.addErrorMessage_block("control-group-salePrice","input-salePrice","销售单价非法,只能输入整数,或带两位小数的数字");
		}else{
			base.clearErrorMessage_block("control-group-salePrice");
		}
		
	});
	
	$("#input-inventory").change(function() {
		
		var inventory=$("#input-inventory").val();
		
		if(isNull(inventory) || !isPositiveInteger(inventory)){
			base.addErrorMessage_block("control-group-inventory","input-inventory","库存数量非法");
		}else{
			base.clearErrorMessage_block("control-group-inventory");
		}
		
	});
	
	$("#input-inventoryWarn").change(function() {
		
		var inventoryWarn=$("#input-inventoryWarn").val();
		
		if(!isNull(inventoryWarn) && !isPositiveInteger(inventoryWarn)){
			base.addErrorMessage_block("control-group-inventoryWarn","input-inventoryWarn","缺货提醒输入非法");
		}else{
			base.clearErrorMessage_block("control-group-inventoryWarn");
		}
		
	});
	$(".swfupload").addClass("btn");
	upload.setCurrentMerCount(0);// 重置当前上传图片数量
	upload.ddf_upload_merchandiseImg("uploadMerchandise", "/shop/" + shopId
			+ "/goods", "$ddf_merchandise.uploadCallBack");

	base.showLoading();
	
	var params={
			
			"merchandiseId":merchandiseId
			
	        };
	
//	DDF_AsyncRequest("POST",ddf.merchandise.getMerchandiseDetail,params,'$ddf_merchandise.loadMerchandiseDetailCallBack(data)');
	eval(Wind.compile("async",function(){
		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.merchandise.getMerchandiseDetail,params));
		loadMerchandiseDetailCallBack(data);
	}))().start();
}



/**
 * 加载商品详情并编辑_回调函数
 */
var merchandiseId,sMerchandiseTypeId,shopId,unitCode,vendorId,parentId,defImgPath="";
function loadMerchandiseDetailCallBack(data){
	base.cancelLoading();
	//alert(data["parentId"]+":"+data["merchandiseTypeId"]);
	
	if(data["code"]==1){
		
		merchandise={
				"barcode":data["barcode"],
				"merchandiseName":data["merchandiseName"],
				"brief":data["brief"],
				"merchandiseTypeId":data["merchandiseTypeId"],
				"perType":data["shopMerchandiseTypeId"],
				"unitName":data["unitName"],
				"inventory":data["inventory"],
				"costPrice":data["costPrice"],
				"mktprice":data["mktprice"],
				"salePrice":data["salePrice"],
				"closed":data["closed"],
				"recommended":data["recommended"],
				"inventoryWarn":data["inventoryWarn"],
				"vendorName":data["vendorName"],
				"detail":data["detail"],
				"seoWeight":data["seoWeight"],
				"shopName":data["shopName"]
		};
		
		$("#input-barcode").val(merchandise["barcode"]);
		$("#input-merchandiseName").val(merchandise["merchandiseName"]);
		$("#input-brief").val(merchandise["brief"]);
		$("#input-inventory").val(merchandise["inventory"]);
		$("#input-costPrice").val(merchandise["costPrice"]);
		$("#input-mktprice").val(merchandise["mktprice"]);
		$("#input-salePrice").val(merchandise["salePrice"]);
		$("#input-inventoryWarn").val(merchandise["inventoryWarn"]);
		$("#input-unitName").val(merchandise["unitName"]);
		$("#input-vendorName").val(merchandise["vendorName"]);
		$("input[name='merchandise.closed'][value='"+merchandise["closed"]+"']").attr("checked",true);
		$("input[name='merchandise.recommended'][value='"+merchandise["recommended"]+"']").attr("checked",true);
		$("input[name='merchandise.seoWeight'][value='"+merchandise["seoWeight"]+"']").attr("checked",true);
		
		base.setRadioStyles();
		
		if(!isNull(data["baseShopId"]) && !isNull(data["baseMerchandiseId"])){
			if(window.location.port == "8082"){
				content = "http://120.27.46.32:8082/mall/reg?m="+data["baseMerchandiseId"];
			}else{
				content = "http://www.storeme.cn/mall/reg?m="+data["baseMerchandiseId"];
			}
			$("#merCode").attr("src",CTX+"/QrCodeServlet?m=" + content+"&w=120&h=120");
		}
		
		
		getErpMerchandiseTypesListSystem(merchandise["merchandiseTypeId"],"NewPage");
		getErpMerchandiseTypesList(merchandise["perType"],"NewPage");
		checkShopMerTypeLength(merchandise["perType"]);
		$.each('#input-merDetail', function() {

			// 加载编辑器
			LoadEditor(merchandise["detail"]);

		});

		getGoodsPicList(merchandiseId);
		picRoll();
		
	}else{
		
		 base.tips_error(data["message"]);
		
	}
	
	 base.cancelLoading();


}
//检测商家自定义分类是否拥有2级分类
function checkShopMerTypeLength(show_shopMerTypeId) {

	var isMerTypeError = false;
	window.setTimeout(function() {

		var obj = $("#shopTNewPage" + show_shopMerTypeId);
		if (obj.parents("ul").hasClass("two_stage")) {
			return;
		}

		var length = $("#shopTNewPage" + show_shopMerTypeId).parents("li")
				.find("ul li").length;
		if (length > 1) {
			isMerTypeError = true;
		} else {
			isMerTypeError = false;
		}

		if (isMerTypeError) {
			shopMerTypeErrorPage();
		}
	}, 1000);
}

/**
 * 获取商品图片
 */
function getGoodsPicList(merchandiseId){
		
	var params={
			
		"merchandiseId":merchandiseId
	};
	
//	DDF_AsyncRequest("POST",ddf.merchandise.getGoodsPhotoList,params,'$ddf_merchandise.getGoodsPicListCallBack(data)');
	eval(Wind.compile("async",function(){
		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.merchandise.getGoodsPhotoList,params));
		getGoodsPicListCallBack(data);
	}))().start();
	
}

/**
 * 获取商品图片_回调函数
 */
function getGoodsPicListCallBack(data){
	
	goodsPicArray=new Array();
	//商品图片列表
	for(var i=0;i<data["goodsPicList"].length;i++){
		
		//$("#goodsPicList").append('<img src="'+fileOpenUrl+data["goodsPicList"][i]["imageUrl"]+'" width="50px" height="50px">');
		if(data["goodsPicList"][i]["def"]==1){
			
			
			
			defImgPath=data["goodsPicList"][i]["imageUrl"];
						
			$("#defImgPath").attr("src",fileOpenUrl+defImgPath);
			
			
			
		}
		
		setGoodsPic("edit",data["goodsPicList"][i]["imageId"],data["goodsPicList"][i]["imageUrl"]);
		
		//<input type='hidden' value='"+dataPath+"' name='goodsPicList["+file.index+"].imageUrl'></input>
		
	}
	if(data["goodsPicList"].length>0){
		upload.setCurrentMerCount(data["goodsPicList"].length);// 设置当前上传图片数量
	}
}


/**
 * 获取系统商品分类
 */		 
function getErpMerchandiseTypesListSystem(showSysT,showPage){

	eval(
			Wind.compile("async", function() {
				var data = $await(wind_async.DDF_AsyncRequest("POST",
						ddf.merchandise.getErpMerchandiseTypesListSystem,
						""));
				getErpMerchandiseTypesListSystemCallBack(data, showSysT,
						showPage);

			}))().start();

}

function getErpMerchandiseTypesListSystemCallBack(data,showSysT,showPage){
	if (data["code"] == "1") {
		var parentHtmlStr = "";
		if (showPage == "searchPage") {
			 parentHtmlStr += '<li><div><p class="nullType"><span id="searchSystemNullType" style="display:block;"><q>全部</q></span></p></div></li>';
			for (var i = 0; i < data["erpMerchandiseTypesListSystem"].length; i++) {
				if (data["erpMerchandiseTypesListSystem"][i]["parentId"] == "") {
					parentHtmlStr += '<li>';
					parentHtmlStr += '<div onclick=$ddf_merchandise.setSysType("'
						+ data["erpMerchandiseTypesListSystem"][i]["merchandiseTypeId"]
					+ '","'
					+ showPage
					+ '")>';
					parentHtmlStr += '<p><i class="icon_add"></i><span id="searchSysT'
							+ data["erpMerchandiseTypesListSystem"][i]["merchandiseTypeId"]
							+ '"><q>'
							+ data["erpMerchandiseTypesListSystem"][i]["merchandiseTypeName"]
							+ '</q></span></p>';
					parentHtmlStr += '</div>';
					parentHtmlStr += '<ul class="two_stage" id="searchType'
							+ data["erpMerchandiseTypesListSystem"][i]["merchandiseTypeId"]
							+ '">';
					parentHtmlStr += '</ul>';
					parentHtmlStr += '</li>';
				}
			}
			$("#searchMerTypeListSystem").html(parentHtmlStr);

			for (var i = 0; i < data["erpMerchandiseTypesListSystem"].length; i++) {
				if (data["erpMerchandiseTypesListSystem"][i]["parentId"] != "") {
					var htmla = '<li onclick=$ddf_merchandise.setSysType("'
							+ data["erpMerchandiseTypesListSystem"][i]["merchandiseTypeId"]
							+ '","'
							+ showPage
							+ '")><p><i class="icon_sub"></i><span id="searchSysT'
							+ data["erpMerchandiseTypesListSystem"][i]["merchandiseTypeId"]
							+ '">'
							+ data["erpMerchandiseTypesListSystem"][i]["merchandiseTypeName"]
							+ '</span></p></li>';
					$(htmla)
							.appendTo(
									"#searchType"
											+ data["erpMerchandiseTypesListSystem"][i]["parentId"]);
				}
			}
			
			//点击“全部”按钮
			$("#searchSystemNullType").bind("click",function(){
//				var val=$(this).find("q").text();
//				$(this).parents(".controls").children(".alert_class").val(val);
//				$(this).parents(".alert_list").hide();
				exports.setSysType("","searchPage");
			});
			
			
		} else {
			for (var i = 0; i < data["erpMerchandiseTypesListSystem"].length; i++) {
				if (data["erpMerchandiseTypesListSystem"][i]["parentId"] == "") {
					parentHtmlStr += '<li>';
					parentHtmlStr += '<div>';
					parentHtmlStr += '<p><i class="icon_add"></i><span id="sysT'
							+ showPage
							+ data["erpMerchandiseTypesListSystem"][i]["merchandiseTypeId"]
							+ '"><q>'
							+ data["erpMerchandiseTypesListSystem"][i]["merchandiseTypeName"]
							+ '</q></span></p>';
					parentHtmlStr += '</div>';
					parentHtmlStr += '<ul class="two_stage" id="type'
							+ showPage
							+ data["erpMerchandiseTypesListSystem"][i]["merchandiseTypeId"]
							+ '">';
					parentHtmlStr += '</ul>';
					parentHtmlStr += '</li>';
				}
			}
			$("#merTypeListSystem" + showPage).html(parentHtmlStr);

			for (var i = 0; i < data["erpMerchandiseTypesListSystem"].length; i++) {
				if (data["erpMerchandiseTypesListSystem"][i]["parentId"] != "") {
					var htmla = '<li onclick=$ddf_merchandise.setSysType("'
							+ data["erpMerchandiseTypesListSystem"][i]["merchandiseTypeId"]
							+ '","'
							+ showPage
							+ '")><p><i class="icon_sub"></i><span id="sysT'
							+ showPage
							+ data["erpMerchandiseTypesListSystem"][i]["merchandiseTypeId"]
							+ '">'
							+ data["erpMerchandiseTypesListSystem"][i]["merchandiseTypeName"]
							+ '</span></p></li>';
					$(htmla)
							.appendTo(
									"#type"
											+ showPage
											+ data["erpMerchandiseTypesListSystem"][i]["parentId"]);
				}
			}
		}

		if (showSysT != null && typeof (showSysT) != "undefined"
				&& !isNull(showSysT)) {
			$("#merTypeListSystemInput").click();
			$("#sysT" + showPage + showSysT).click();
		}

	} else {
		base.tips_error(data["message"]);
	}
}

//设置系统类型
exports.setSysType = function(_sysType, showPage) {

	if (showPage == "searchPage") {
		searchSysType = _sysType;
	} else {
		sysType = _sysType;
	}

	clearErrorMessage("control-group-merTypeListSystemInput");// 消除错误提示
};



/**
 * 获取商品自定义分类
 */		 
function getErpMerchandiseTypesList(showShopT,showPage){

	eval(
			Wind.compile("async", function() {
				var data = $await(wind_async.DDF_AsyncRequest("POST",
						ddf.merchandise.getErpMerchandiseTypesList, ""));
				getErpMerchandiseTypesListCallBack(data, showShopT,
						showPage);

			}))().start();

}
/**
 * 获取获取商品分类_回调函数
 */
function getErpMerchandiseTypesListCallBack(data,showShopT,showPage){
	if (data["code"] == "1") {
		var parentHtmlStr = "";
		if (showPage == "searchPage") {
			parentHtmlStr += '<li onclick=$ddf_merchandise.setPerType("","'
					+ showPage
					+ '")><div><p class="nullType"><span id="searchNullType" ><q>全部</q></span></p><div></li>';
			for (var i = 0; i < data["erpMerchandiseTypesList"].length; i++) {
				if (data["erpMerchandiseTypesList"][i]["parentId"] == "") {
					parentHtmlStr += '<li id="search'
							+ data["erpMerchandiseTypesList"][i]["merchandiseTypeId"]
							+ '">';
					parentHtmlStr += '<div onclick=$ddf_merchandise.setPerType("'
							+ data["erpMerchandiseTypesList"][i]["merchandiseTypeId"]
							+ '","'
							+ showPage
							+ '")><p><i class="icon_add"></i><span id="searchShopT'
							+ data["erpMerchandiseTypesList"][i]["merchandiseTypeId"]
							+ '"><q>'
							+ data["erpMerchandiseTypesList"][i]["merchandiseTypeName"]
							+ '</q></span>';
					parentHtmlStr += '</p></div>';
					parentHtmlStr += '<ul class="two_stage">';
					parentHtmlStr += '<li id="searchPtype'
							+ data["erpMerchandiseTypesList"][i]["merchandiseTypeId"]
							+ '">';
					parentHtmlStr += '</li>';
					parentHtmlStr += '</ul>';
					parentHtmlStr += '</li>';
				}
			}
			$("#searchMerTypeListP").html(parentHtmlStr);

			for (var i = 0; i < data["erpMerchandiseTypesList"].length; i++) {
				if (data["erpMerchandiseTypesList"][i]["parentId"] != "") {
					var html = '';
					html += '<li id="search'
							+ data["erpMerchandiseTypesList"][i]["merchandiseTypeId"]
							+ '" onclick=$ddf_merchandise.setPerType("'
							+ data["erpMerchandiseTypesList"][i]["merchandiseTypeId"]
							+ '","'
							+ showPage
							+ '")><div><p class="second_p"><i class="icon_sub"></i><span id="searchShopT'
							+ data["erpMerchandiseTypesList"][i]["merchandiseTypeId"]
							+ '">'
							+ data["erpMerchandiseTypesList"][i]["merchandiseTypeName"]
							+ '</span>';
					html += '</p></div></li>';
					$(html)
							.insertBefore(
									"#searchPtype"
											+ data["erpMerchandiseTypesList"][i]["parentId"]);
				}
			}
			// $("#merTypeListPInput").click();
		} else {
			parentHtmlStr += '<li onclick=$ddf_merchandise.setPerType("","'
					+ showPage
					+ '")><p class="nullType"><span id="nullType'
					+ showPage + '" ><q>无分类</q></span></p></li>';

			for (var i = 0; i < data["erpMerchandiseTypesList"].length; i++) {
				if (data["erpMerchandiseTypesList"][i]["parentId"] == "") {
					parentHtmlStr += '<li id="'
							+ data["erpMerchandiseTypesList"][i]["merchandiseTypeId"]
							+ '">';
					parentHtmlStr += '<div onclick=$ddf_merchandise.setPerType("'
							+ data["erpMerchandiseTypesList"][i]["merchandiseTypeId"]
							+ '","'
							+ showPage
							+ '")><p><i class="icon_add"></i><span id="shopT'
							+ showPage
							+ data["erpMerchandiseTypesList"][i]["merchandiseTypeId"]
							+ '"><q>'
							+ data["erpMerchandiseTypesList"][i]["merchandiseTypeName"]
							+ '</q></span>';
					parentHtmlStr += '<a class="alert_list2_right" >删除</a>';
					parentHtmlStr += '</p></div>';
					parentHtmlStr += '<ul class="two_stage">';
					parentHtmlStr += '<li id="ptype'
							+ showPage
							+ data["erpMerchandiseTypesList"][i]["merchandiseTypeId"]
							+ '">';
					parentHtmlStr += '<label><input type="text" class="span3" placeholder="二级分类名称" /><button id="ptypesb'
							+ showPage
							+ data["erpMerchandiseTypesList"][i]["merchandiseTypeId"]
							+ '" class="btn second_class" type="button" onclick=$ddf_merchandise.addSecondType("'
							+ data["erpMerchandiseTypesList"][i]["merchandiseTypeId"]
							+ '","' + showPage + '")>添加二级分类</button></label>';
					parentHtmlStr += '</li>';
					parentHtmlStr += '</ul>';
					parentHtmlStr += '</li>';
				}
			}
			parentHtmlStr += '<li>';
			parentHtmlStr += '<label><input type="text" class="span3" placeholder="一级分类名称" /><button id="ptypefb'
					+ showPage
					+ '" class="btn first_class" type="button" onclick=$ddf_merchandise.addFirstType("'
					+ showPage + '")>添加一级分类</button></label>';
			parentHtmlStr += '</li>';
			$("#merTypeListP" + showPage).html(parentHtmlStr);

			for (var i = 0; i < data["erpMerchandiseTypesList"].length; i++) {
				if (data["erpMerchandiseTypesList"][i]["parentId"] != "") {
					var html = '';
					html += '<li id="'
							+ data["erpMerchandiseTypesList"][i]["merchandiseTypeId"]
							+ '" onclick=$ddf_merchandise.setPerType("'
							+ data["erpMerchandiseTypesList"][i]["merchandiseTypeId"]
							+ '","'
							+ showPage
							+ '")><div><p class="second_p"><i class="icon_sub"></i><span id="shopT'
							+ showPage
							+ data["erpMerchandiseTypesList"][i]["merchandiseTypeId"]
							+ '">'
							+ data["erpMerchandiseTypesList"][i]["merchandiseTypeName"]
							+ '</span>';
					html += '<a class="alert_list2_right">删除</a>';
					html += '</p></div></li>';
					$(html)
							.insertBefore(
									"#ptype"
											+ showPage
											+ data["erpMerchandiseTypesList"][i]["parentId"]);
				}
			}

			if (showShopT != "newMer") {
				$("#merTypeListPInput").click();
			}
		}
		// $("#merTypeListInput").val("haohaohao");
		if (showShopT == "" || typeof (showShopT) == "undefined") {
			$("#nullType" + showPage).click();
		} else {
			$("#shopT" + showPage + showShopT).click();
		}

	} else {
		base.tips_error(data["message"]);
	}

	base.cancelLoading();

}

//设置自定义分类
exports.setPerType=function(_perType,showPage){
	if (showPage == "searchPage") {
		searchPerType = _perType;
	} else {
		perType = _perType;
	}
}

//新建一级分类
exports.addFirstType=function(showPage){
	var obj=$("#ptypefb"+showPage);
	var val_t=obj.siblings("input").val();
	if(!isNull(val_t)){
		addFirstType(val_t,showPage);
	}
}

function addFirstType(typeName,showPage){
	var param={
			"parentId":"",
			"merchandiseTypeName":typeName
	};
	
	eval(Wind.compile("async",function(){
		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.merchandise.addMerchandiseType,param));
		addFirstTypeCallBack(data,showPage);

	}))().start();
	
}

function addFirstTypeCallBack(data,showPage){
	if (data["code"] == "1") {
		var obj = $("#ptypefb" + showPage);
		var val_t = obj.siblings("input").val();

		var _html = '<li id="'
				+ data["merchandiseTypeId"]
				+ '"><div onclick=$ddf_merchandise.setPerType("'
				+ data["merchandiseTypeId"]
				+ '")><p><i class="icon_add"></i><span id="shopT'
				+ showPage
				+ data["merchandiseTypeId"]
				+ '"><q>'
				+ val_t
				+ '</q></span><a class="alert_list2_right">删除</a></p></div><ul class="two_stage"><li id="ptype'
				+ showPage
				+ data["merchandiseTypeId"]
				+ '"><label><input type="text" class="span3" placeholder="二级分类名称" /><button id="ptypesb'
				+ showPage
				+ data["merchandiseTypeId"]
				+ '" class="btn second_class" type="button" onclick=$ddf_merchandise.addSecondType("'
				+ data["merchandiseTypeId"] + '","' + showPage
				+ '")>添加二级分类</button></label></li></ul></li>';
		obj.parent().parent().before(_html);
		obj.siblings("input").val("");
	}
}

//新建二级分类
exports.addSecondType=function(id,showPage){
	var obj = $("#ptypesb" + showPage + id);
	var val_t2 = obj.siblings("input").val();
	addSecondType(id, val_t2, showPage);
}

function addSecondType(parentId,typeName,showPage){
		var param = {
			"parentId" : parentId,
			"merchandiseTypeName" : typeName
		};

		eval(
				Wind.compile("async", function() {
					var data = $await(wind_async.DDF_AsyncRequest("POST",
							ddf.merchandise.addMerchandiseType, param));
					addSecondTypeCallBack(parentId, data, showPage);

				}))().start();

	}

function addSecondTypeCallBack(id,data, showPage){
	var obj = $("#ptypesb" + showPage + id);
	var val_t2 = obj.siblings("input").val();
	if (!isNull(val_t2)) {
		var _html2 = '<li id="'
				+ data["merchandiseTypeId"]
				+ '" onclick=$ddf_merchandise.setPerType("'
				+ data["merchandiseTypeId"]
				+ '")><div><p class="second_p"><i class="icon_sub"></i><span id="shopT'
				+ showPage + data["merchandiseTypeId"] + '">' + val_t2
				+ '</span><a class="alert_list2_right">删除</a></p></div>';
		obj.parent().parent().before(_html2);
		obj.siblings("input").val("");
	}
}


//删除分类
$(document).on("click",".alert_list2_right",function(){
//	$(this).parent().parent().remove();
//	$(this).css("background","#333");
	exports.deleteType($(this).parent().parent().parent().attr("id"));
});

exports.deleteType=function(typeId,isBatch){
	var param={
			"merchandiseTypeId":typeId
	};
	eval(Wind.compile("async",function(){
		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.merchandise.deleteMerchandiseType,param));
		deleteTypeCallBack(typeId,isBatch,data);

	}))().start();
	
};

function deleteTypeCallBack(typeId,isBatch,data){
	
	if (data["code"] == "1") {
		$("#" + typeId).remove();
		
		if(isBatch){
			showTipsInBatch("删除分类成功！");
//			$("#errorMsgBath").css("display", "block");
//			$("#errorMsgBath").find("span").html("删除分类成功！");
		}else{
			base.tips("删除分类成功！");
		}
		
		
	} else {
		// getErpMerchandiseTypesList(merchandise["perType"],"NewPage");
//		alert($("#" + typeId).parents("div .batch").html());
		if(isBatch){
			showTipsInBatch(data["message"]);
//			$("#errorMsgBath").css("display", "block");
//			$("#errorMsgBath").find("span").html(data["message"]);
		}else{
			base.tips_error(data["message"]);
		}
	}
}


/**
 * 设置商品图片
 */
var goodsPicArray=new Array();

function setGoodsPic(type,imageId,dataPath){
	
    if(type=="add"){
    	
    	$("#goodsPicList").append('<li><p><img src="'+fileOpenUrl+dataPath+'"></p><div class="setNdelete"><span class="set_cover" onclick=$ddf_merchandise.setDefaultGoodsPic(this,"'+dataPath+'") title="设为默认"></span><span class="delete_pic" onclick=$ddf_merchandise.delGoodsPic(this) title="删除图片"></span></div></li>');

    }else{
    	
    	$("#goodsPicList").append('<li><p><img src="'+fileOpenUrl+dataPath+'"></p><div class="setNdelete"><span class="set_cover" onclick=$ddf_merchandise.setDefaultGoodsPic(this,"'+dataPath+'") title="设为默认"></span><span class="delete_pic" onclick=$ddf_merchandise.delPic(this,"'+imageId+'") title="删除图片"></span></div></li>');

    	
    }

	goodsPicArray.push(dataPath);
	
	$("#product_pic li").mouseover(function(){
		  $(this).children(".setNdelete").animate({bottom:0},100);
	});
	$("#product_pic li").mouseleave(function(){
		  $(this).children(".setNdelete").animate({bottom:-25+"px"},100);
	});
	
	//如果默认图片为空,则上传第一张自动设置为默认图片
	if(isNull(defImgPath)){
		
		defImgPath=dataPath;
		
		$("#defImgPath").attr("src",fileOpenUrl+dataPath);
		
	}

	//<input type='hidden' value='"+dataPath+"' name='goodsPicList["+file.index+"].imageUrl'></input>

}

/**
 * 设置默认图片
 */

function setDefaultGoodsPic(obj,_defImgPath){
	
	var index=$(obj).parent().parent().index();
	
	defImgPath=_defImgPath;
	
	goodsPicArray[index]=defImgPath;
	
	$("#defImgPath").attr("src",fileOpenUrl+defImgPath);
	
}

/**
 * 删除图片
 */

function delGoodsPic(obj){
	
	var index=$(obj).parent().parent().index();
	
	//如果删除的图片是默认图片
	if(goodsPicArray[index]==defImgPath){
		
		defImgPath="";
		
		$("#defImgPath").attr("src","img/pic_bg.png");
		
	}
	
	goodsPicArray=goodsPicArray.del(index);
	
	$(obj).parent().parent().remove();
	
}

/**
 * 删除图片(删除数据库的图片)
 */
var imageObj;

function delPic(obj,image_id){
	
	imageObj=obj;
	var params={
			"image_id":image_id
	        };
	
	base.showLoading();
	
//	DDF_AsyncRequest("POST",ddf.merchandise.delPic,params,'$ddf_merchandise.delPicCallBack(data)');
	eval(Wind.compile("async",function(){
		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.merchandise.delPic,params));
		delPicCallBack(data);
	}))().start();
}

/**
 * 删除图片_回调函数
 * @param data
 */
function delPicCallBack(data){
	
	if(data["code"]==1){
		
		delGoodsPic(imageObj);
		
	}else{
		
		
		
	}
	base.cancelLoading();
}


exports.updateNext=function(){
	var barcode=$("#input-barcode").val();

	if(!isEnglishNO(barcode)){
		base.addErrorMessage_block("control-group-barcode","input-barcode","条形码非法");
		return;
	}else if(isNull(barcode)||barcode==merchandise["barcode"]){
		exports.updateandNext();
	}else{
		var params={
				"barcode":barcode
		}
		eval(Wind.compile("async",function(){
			var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.merchandise.checkBarcode,params));
			checkupdateBarcodeCallBack(data);
		}))().start();
	}
	
}

function checkupdateBarcodeCallBack(data){
	if(data["code"]=="1"){
		exports.updateandNext();
	}else{
		base.tips_error(data["message"]);
	}
}

exports.updateandNext=function(){
	var barcode=$("#input-barcode").val();
	var merchandiseName=$("#input-merchandiseName").val();
	var brief=$("#input-brief").val();
	
	var costPrice=$("#input-costPrice").val();
	var mktprice=$("#input-mktprice").val();
	var salePrice=$("#input-salePrice").val();
	var inventory=$("#input-inventory").val();
	var unitName=$("#input-unitName").val();
	var vendorName=$("#input-vendorName").val();
	var closed=$('input[name="merchandise.closed"]:checked').val();
	var recommended=$('input[name="merchandise.recommended"]:checked').val();
	var inventoryWarn=$("#input-inventoryWarn").val();
	var seoWeight=$('input[name="merchandise.seoWeight"]:checked').val();
	var memo = kindEditor.html();
	if(!isEnglishNO(barcode)){
		base.addErrorMessage_block("control-group-barcode","input-barcode","条形码非法");
		return;
	}
	if(isNull(merchandiseName)){
		baseaddErrorMessage_block("control-group-merchandiseName","input-merchandiseName","商品名称非法");
		return;
	}
	if(isLength(merchandiseName,80)){
		base.addErrorMessage_block("control-group-merchandiseName","input-merchandiseName","商品名称不要超过40个字");
		return;
	}

	if(isLength(brief,100)){

		base.addErrorMessage_block("control-group-brief","input-brief","商品简介不要超过50个字");
		return;
	}

	if(isNull(sysType)){
		base.tips_error("请选择商品分类");
		return;
	}

	if(!isMerPrice(costPrice)){
		base.addErrorMessage_block("control-group-costPrice","input-costPrice","成本单价非法,只能输入整数,或带两位小数的数字");
		return;
	}

	if(!isMerPrice(mktprice)){
		base.addErrorMessage_block("control-group-mktprice","input-mktprice","市场价格非法,只能输入整数,或带两位小数的数字");
		return;
	}

	if(isNull(salePrice) || !isMerPrice(salePrice)){
		base.addErrorMessage_block("control-group-salePrice","input-salePrice","销售单价非法,只能输入整数,或带两位小数的数字");
		return;
	}

	if(isNull(inventory) || !isPositiveInteger(inventory)){
		base.addErrorMessage_block("control-group-inventory","input-inventory","库存数量非法");
		return;
	}
	
	if(!isNull(inventoryWarn) && !isPositiveInteger(inventoryWarn)){
		base.addErrorMessage_block("control-group-inventoryWarn","input-inventoryWarn","缺货提醒输入非法");
		return;
	}
	

	params={
			"barcode":barcode,
			"merchandiseName":merchandiseName,
			"brief":brief,
			"merchandiseId" : merchandiseId,
			"merchandiseTypeId":sysType,
			"perType":perType,
			"unitName":unitName,
			"inventory":inventory,
			"costPrice":costPrice,
			"mktprice":mktprice,
			"salePrice":salePrice,
			"closed":closed,
			"recommended":recommended,
			"inventoryWarn":inventoryWarn,
			"vendorName":vendorName,
			"seoWeight":seoWeight,
			"detail":memo,
			"defImgPath" : defImgPath
	};
	
	
	$("#top_merchandiseName").html(merchandiseName);
	for (var i = 0; i < goodsPicArray.length; i++) {

		if (isNull(defImgPath)) {

			defImgPath = goodsPicArray[0];

			params["defImgPath"] = defImgPath;
		}

		params["goodsPicList[" + i + "].imageUrl"] = goodsPicArray[i];

	}

	base.showLoading();

	eval(
			Wind.compile("async", function() {
				var data = $await(wind_async.DDF_AsyncRequest("POST",
						ddf.merchandise.updateGoodsInfoById, params));
				updateandNextCallBack(data);
			}))().start();
}
function updateandNextCallBack(data) {
	if (data["code"] == "1") {
		base.tips("保存商品成功！");
		showDiv("content0");
		base.cancelLoading();
		sort="1";
		$("#searchMerBtn").click();
	} else {
		base.tips_error(data["message"]);
		base.cancelLoading();

	}

}

exports.updateNextPage=function(){
	var htmlStr="";
	
	htmlStr += '<div id="content-header">';
	htmlStr += '<div id="breadcrumb"> <a href=javascript:load("'+ddf.index.index_js+'",1,"$ddf_index.loadIndex","") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href=javascript:$ddf_merchandise.showDiv("content0")>商品管理</a><a href="javascript:void(0)" class="current">更新商品</a><a href="javascript:void(0)" class="current" id="top_merchandiseName"></a></div>';
	htmlStr += '</div>    ';

	htmlStr += '<div class="container-fluid">';
	htmlStr += '<div class="row-fluid">';
	htmlStr += '<div class="span12">    	';
	htmlStr += '<div id="alert-tips1" ></div>';
	htmlStr +='<div id="errorMessage-addMer" style="display:none" class="alert alert-error alert-block">';
	htmlStr +='<a class="close" href="#" data-dismiss="alert">×</a>';
	htmlStr +='<h4 class="alert-heading">Error!</h4>';
	htmlStr +='You are not looking too good. Nulla vitae elit libero, a pharetra augue. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.';
	htmlStr +='</div>  ';
	
	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title"> <span class="icon"><i class="icon-th"></i></span>';
	htmlStr += '<h5>商品信息</h5>';
	htmlStr += '</div>';
	htmlStr += '<div class="widget-content nopadding">';
	htmlStr += '<div class="form-horizontal">	';
	
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">商品图片：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<div class="upload_box">';
	htmlStr += '<span id="uploadMerchandise"></span>';
	htmlStr += '<div style="display:none;" class="progress progress-success progress-striped ">';
	htmlStr += '<div class="bar" style="width: 0%;" id="prencentIcon"></div>  ';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '<div class="picture">';
	htmlStr += '<div class="default_pic"><p><img id="defImgPath" src="../img/pic_bg.png"></p><div class="setDefault">默认图片</div></div>';
	htmlStr += '<div class="pic_btn_left" style="display: block;"></div>';
	htmlStr += '<div class="product_pic" id="product_pic" style="width: 504px;">      ';
	htmlStr += '<ul style="width: 840px;" id="goodsPicList" >';
	htmlStr += '</ul>';
	htmlStr += '</div>';
	htmlStr += '<div class="pic_btn_right" style="display: block;"></div>';
	htmlStr += '</div>';
	htmlStr += '<span class="help-block">说明：图片尺寸为宽1080*高540 ，图片大小不能超过1MB，图片格式为jpg、png</span>';
	htmlStr += '</div>     ';
	htmlStr += '</div>';
	
	htmlStr += '<div class="control-group" id="control-group-merDetail">';
	htmlStr += '<label class="control-label">商品详情：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<textarea name="content" id="input-merDetail" style="width:800px;height:400px;"></textarea>';
	htmlStr += '</div>                   ';
	htmlStr += '</div>';
	

	htmlStr += '<div class="form-actions">';
	htmlStr += '<button class="btn btn-primary" type="button" onclick=$ddf_merchandise.updateFinish() >保存</button>';
	htmlStr += ' <button class="btn btn-info" type="button" onClick=$ddf_merchandise.showDiv("content2")>返回</button>      ';
	htmlStr += '</div>  ';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div> ';
	htmlStr += '</div>';
	htmlStr += '</div> ';
	htmlStr += '</div> ';
	
	showDiv("content20");
	$("#content19").html("");
	$("#content20").html(htmlStr);
	
	picRoll();
	
	$(".swfupload").addClass("btn");

	upload.ddf_upload_merchandiseImg("uploadMerchandise","/shop/"+shopId+"/goods","$ddf_merchandise.uploadCallBack");
	$.each('#input-merDetail', function() {
		 
        // 加载编辑器
        LoadEditor(merchandise["detail"]);

    });
	
	getGoodsPicList(merchandiseId);
	
};


exports.updateFinish=function(){
var memo=kindEditor.html();
	var params={
			"merchandiseId":merchandiseId,
			"barcode":updateMerchandise["barcode"],
			"merchandiseName":updateMerchandise["merchandiseName"],
			"brief":updateMerchandise["brief"],
			"merchandiseTypeId":updateMerchandise["merchandiseTypeId"],
			"perType":updateMerchandise["perType"],
			"unitName":updateMerchandise["unitName"],
			"inventory":updateMerchandise["inventory"],
			"costPrice":updateMerchandise["costPrice"],
			"mktprice":updateMerchandise["mktprice"],
			"salePrice":updateMerchandise["salePrice"],
			"vendorName":updateMerchandise["vendorName"],
			"closed":updateMerchandise["closed"],
			"recommended":updateMerchandise["recommended"],
			"inventoryWarn":updateMerchandise["inventoryWarn"],
			"detail":memo,
			"defImgPath":defImgPath,
			"seoWeight":updateMerchandise["seoWeight"]
			
	};
	
	
	for(var i=0;i<goodsPicArray.length;i++){
		
		if(isNull(defImgPath)){
			
			defImgPath=goodsPicArray[0];

			params["defImgPath"]=defImgPath;
		}
		
		params["goodsPicList["+i+"].imageUrl"]=goodsPicArray[i];
		
	}
	
	base.showLoading();
	
	eval(Wind.compile("async",function(){
		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.merchandise.updateGoodsInfoById,params));
		updateMerchandiseCallBack(data);
	}))().start();
}


/**
 * 修改商品信息_回调函数
 */
function updateMerchandiseCallBack(data){
	
	
	if(data["code"]==1){
		
//		back("content2","content0");
		showDiv("content0");
		
		base.tips("修改商品成功");
		
		$("#searchMerBtn").click();// 刷新列表

	}else{
		
		base.tips_error(data["message"]);
		
    }
	
	merchandise={};//商品属性数组
	updateMerchandise={};

	base.cancelLoading();

	
}


/**
 * 打开商品单位列表
 */
exports.openMerUnitDialog=function(){

	dialog.ddf_dialog_mer_unit($("#input-unit"),function(id,name){  
		
		unitCode=id;
		
		$("#input-unit").val(name);
		setUnitsName(name);
	
		
    });
	
}

/**
 * 设置生产厂家
 */

function setVendors(id,name){
	
	vendorId=id;
	
	$("#input-vendorName").val(name);
}

/**
 * 打开厂家列表
 */
exports.openVendorDialog=function(){

	dialog.ddf_dialog_vendor($("#input-vendorName"),"goods",function(id,name){  

		setVendors(id,name);
		
    });
	
};
/**
 * 设置商品优先度
 */
exports.setSeoWeight = function(showName, id, name) {

	if (showName == "searchSeoWeightName") {
		searchSeoWeight = id;
	} else {
		seoWeight = id;
	}
	$("#" + showName).html(name);
};




function showDiv(block){
	
	$("#content > div").hide();
	
	if($("#"+block).length<=0){
		
		$("#content").append('<div id="'+block+'"></div>'); 
		
	}else{
		
		$("#"+block).show();
	}
	
	if(block=="content0"){
		
		shopTypeId="";
		goodsPicArray=new Array();
	}
	if(block=="content1"){
		$("#content2").html("");
	}
	if(block=="content3"){
		parentTypeId="";
	}
}

//更新时间排序
exports.operTimeSort = function() {
	if ($("#operTimeSort").hasClass("on")) {
		if (!$("#operTimeSort").hasClass("up")) {
			sort = "2";
			$("#operTimeSort").addClass("up");
		} else {
			sort = "1";
			$("#operTimeSort").removeClass("up");
		}
	} else {
		$("#operTimeSort").siblings(".btn-tab").removeClass("on up");
		sort = "1";
		$("#operTimeSort").addClass("on");
	}

	getMerchandiseList(1, pageSize, keywordsType, keywords, merStatus);
};

// 排序优先度排序
exports.seoWeightSort = function() {
	if ($("#seoWeightSort").hasClass("on")) {
		if (!$("#seoWeightSort").hasClass("up")) {
			sort = "4";
			$("#seoWeightSort").addClass("up");
		} else {
			sort = "3";
			$("#seoWeightSort").removeClass("up");
		}
	} else {
		$("#seoWeightSort").siblings(".btn-tab").removeClass("on up");
		sort = "3";
		$("#seoWeightSort").addClass("on");
	}
	getMerchandiseList(1, pageSize, keywordsType, keywords, merStatus);

};

// 库存量排序
exports.inventorySort = function() {
	if ($("#inventorySort").hasClass("on")) {
		if (!$("#inventorySort").hasClass("up")) {
			sort = "6";
			$("#inventorySort").addClass("up");
		} else {
			sort = "5";
			$("#inventorySort").removeClass("up");
		}
	} else {
		$("#inventorySort").siblings(".btn-tab").removeClass("on up");
		sort = "5";
		$("#inventorySort").addClass("on");
	}
	getMerchandiseList(1, pageSize, keywordsType, keywords, merStatus);
};

// 销售量排序
exports.saleSort = function() {
	if ($("#saleSort").hasClass("on")) {
		if (!$("#saleSort").hasClass("up")) {
			sort = "8";
			$("#saleSort").addClass("up");
		} else {
			sort = "7";
			$("#saleSort").removeClass("up");
		}
	} else {
		$("#saleSort").siblings(".btn-tab").removeClass("on up");
		sort = "7";
		$("#saleSort").addClass("on");
	}
	getMerchandiseList(1, pageSize, keywordsType, keywords, merStatus);
};

// 销售价排序
exports.priceSort = function() {
	if ($("#priceSort").hasClass("on")) {
		if (!$("#priceSort").hasClass("up")) {
			sort = "10";
			$("#priceSort").addClass("up");
		} else {
			sort = "9";
			$("#priceSort").removeClass("up");
		}
	} else {
		$("#priceSort").siblings(".btn-tab").removeClass("on up");
		sort = "9";
		$("#priceSort").addClass("on");
	}
	getMerchandiseList(1, pageSize, keywordsType, keywords, merStatus);
};

// 销售价排序
exports.defSort = function() {
		$("#defSort").siblings(".btn-tab").removeClass("on up");
		sort = "";
	getMerchandiseList(1, pageSize, keywordsType, keywords, merStatus);
};


exports.showDownMerCode  = function() {

	var divcont = '<div class="big_modal" id="showDownId" style="margin-top:'+myScrollTop+'px">'
			+ '<div class="modal-header">'
			+ '<button class="close over" type="button">×</button>'
			+ '<h3>二维码尺寸</h3>'
			+ '</div>'
			+ '<div>'
			+ '<div class="widget-content nopadding dataTables_wrapper">'
			+ '<table class="table table-bordered data-table">'
			 + '<thead>' + '<tr>'
			+ '<th>二维码边长(cm)</th>' + '<th>建议扫描距离(米)</th>' + '<th>下载链接</th>'  + '</tr>'
			+ '</thead>' + '<tbody id="">' 
			+ '<tr><td class="center">8cm</td><td class="center">0.5m</td><td class="center"><a href="javascript:$ddf_merchandise.downCode(1);">下载</a></td></tr>'
			+ '<tr><td class="center">12cm</td><td class="center">0.8m</td><td class="center"><a href="javascript:$ddf_merchandise.downCode(2);">下载</a></td></tr>'
			+ '<tr><td class="center">15cm</td><td class="center">1m</td><td class="center"><a href="javascript:$ddf_merchandise.downCode(3);">下载</a></td></tr>'
//			+ '<tr><td class="center">30cm</td><td class="center">1.5m</td><td class="center"><a href="javascript:$$ddf_merchandise.downCode(4);">下载</a></td></tr>'
//			+ '<tr><td class="center">50cm</td><td class="center">2.5m</td><td class="center"><a href="javascript:$$ddf_merchandise.downCode(5);">下载</a></td></tr>'
			+ '</tbody>'
			+ '</table>'  + '</div>'
			+ '</div>' + '</div>'
			+ '<div class="big_modal-backdrop in"></div>';

	$(divcont).appendTo("body");

	$("#showDownId").find(".over").click(
		function() {$("#showDownId").remove();
			$("body .big_modal-backdrop").remove();
		});
}

/**
 * 下载二维码
 */
exports.downCode=function(_size){
	$("#showDownId").remove();
	$("body .big_modal-backdrop").remove();
	
	var size = "";
	if(_size == 1){
		size = "&w=945&h=945";
	}else if(_size == 2){
		size = "&w=1417&h=1417";
	}else if(_size == 3){
		size = "&w=1772&h=1772";
	}else if(_size == 4){
		size = "&w=3543&h=3543";
	}else if(_size == 5){
		size = "&w=5906&h=5906";
	}else{
		size = "&w=945&h=945";
	}
	
    var image = CTX+"/QrCodeServlet?m=" + content+size;   
    
    var filename = '云便利商店_' + merchandise["shopName"] + '_' + $("#input-merchandiseName").val() + '.png'  ;
    
    if(document.all) {//IE用
        window.frames["hrong"].location.href   =   image;     
        $ddf_shop.sa();   
    }else if (document.createEvent) {
    	var save_link = document.createElement("a");
        save_link.href = image;
        save_link.download = filename;

        var event = document.createEvent('MouseEvents');
        event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
        save_link.dispatchEvent(event);
    }
};

var myScrollTop=0;
window.onscroll=function(){	
	function get_scrollTop_of_body(){ //scrollTop能力检测函数
				var scrollTop; 
				if(typeof window.pageYOffset != 'undefined'){ 
				scrollTop = window.pageYOffset; 
				} 
				else 
				if(typeof document.compatMode != 'undefined' && 
				document.compatMode != 'BackCompat'){ 
				scrollTop = document.documentElement.scrollTop; 
				} 
				else 
				if(typeof document.body != 'undefined'){ 
				scrollTop = document.body.scrollTop; 
				} 
				return scrollTop; 
	}
	 myScrollTop = parseInt(get_scrollTop_of_body());//获取ScrollTop的值
}

//暴露方法
//exports={};
//exports.loadMerchandiseList=loadMerchandiseList;
exports.getMerchandiseList=getMerchandiseList;
exports.getMerchandiseListCallBack=getMerchandiseListCallBack;
exports.resetSearchParams=resetSearchParams;
exports.searchMerchandise=searchMerchandise;
exports.setKeywordsType=setKeywordsType;
exports.setMerStatus=setMerStatus;
exports.openAddMerchandise=openAddMerchandise;
exports.addMerchandiseCallBack=addMerchandiseCallBack;
exports.loadMerchandiseDetail=loadMerchandiseDetail;
exports.loadMerchandiseDetailCallBack=loadMerchandiseDetailCallBack;

exports.getGoodsPicListCallBack=getGoodsPicListCallBack;
exports.getErpMerchandiseTypesList=getErpMerchandiseTypesList;
exports.getErpMerchandiseTypesListCallBack=getErpMerchandiseTypesListCallBack;
exports.setGoodsPic=setGoodsPic;
exports.setDefaultGoodsPic=setDefaultGoodsPic;
exports.delGoodsPic=delGoodsPic;
exports.delPic=delPic;
exports.delPicCallBack=delPicCallBack;
exports.updateMerchandiseCallBack=updateMerchandiseCallBack;
exports.showDiv = showDiv;
});
//})();